Segfault parsing 32 options bug
This patch fixes a bug where cfagent segfaults if more than 31 arguments are passed on the command line.
This patch was merged into cfengine 2.2.3.
Download
Argument parsing fix for cfengine 2.2.1
Discussion
This bug arises from a workaround for a problem when cfagent is called from a shell script with magic such as
#!/bla/cfengine -v -f
The arguments end up being passed to cfagent as a single string. Code to work around this problem by constructing an array of arguments parsed from the commandline.
However, this array is declared statically of size CF_MAXARGS (31) and cfagent segfaults if more than this number are provided.
This patch corrects this behaviour by parsing the arguments in two passes. First the number of actual arguments is counted and a dynamic buffer is allocated. Then the command line is split as before.