bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Static analysis of bash scripts


From: Daniel Reichelt
Subject: Static analysis of bash scripts
Date: Tue, 02 Apr 2013 10:54:37 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20121215 Icedove/3.0.11

Hi everyone,

I'm maintaining a collection of shell scripts in some 50 different
debian packages. Some of them have no dependencies (with respect to
external commands), some of them depend on other debian packages and
some depend on each other.

I have grown sick of dependency management, yet I want it to be clean
and - newly - automated as far as possible. There are a hand full of
perl scripts out there to parse bash scripts in a "print every 1st word
on a line or whatever stands after a semicolon or a pipe" kind of way
which didn't satisfy me at all.

So I thought why re-invent the wheel...bash already has it's own parser,
why not use it to print every would-be-issued-command?

I did some hacking and came up with the attached patches, which
- add a new command-line option -N (implying -n)
- acts like a "verbose noexec" flag: walk the syntax tree and print each
command with its associated command type.


Currently it's in POC state and I'd like to hear your thoughts and I
have a few questions of my own:
- Would this feature be considered to be included upstream?
- What needs adjustment to be considered (style, technical reasons)?


There are some constructs which still aren't covered and I'm gonna need
help with:
1   a=$(( $(foo) + $(bar) ))
2   $(foo)
3   `foo`
4   case $(foo) in
5   < <(foo)

- 1 through 3 show up as simple_commands with the assignment flag set
but are not further evaluated by the parser (I guess that happens at
runtime...)
- 3 shows up as case_cmd, however unevaluated otherwise as above
- 5 doesn't show up at all in the output of ./bash-patched -nN
./testscript.sh


I don't have any knowledge of the inner workings of parser.y let alone
how to use it or how bash interacts with it - I just happened to have
found the right place to hook into...do you have an idea how to cover these?

Thanks
Daniel

Attachment: 0001-add-flag-N.patch
Description: Text Data

Attachment: 0002-print-command-type-in-eval.c-and-adjust-Makefile.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]