diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-15 20:34:15 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-15 20:34:15 +0000 |
commit | 40c123148a9d84218667124a97283f7cb93bfa50 (patch) | |
tree | 58fcbb765089e53d2874200e8f282051e3f699f0 /lib | |
parent | ffab7ee68b32d44ae2f35f688f417cd0109b0b45 (diff) | |
download | monitoring-plugins-40c123148a9d84218667124a97283f7cb93bfa50.tar.gz |
Fix handling of leading and trailing spaces in stanza
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1947 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parse_ini.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index b555316e..38bcb39b 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
@@ -126,6 +126,8 @@ static np_arg_list* read_defaults(FILE *f, const char *stanza){ | |||
126 | stanzastate=WRONGSTANZA; | 126 | stanzastate=WRONGSTANZA; |
127 | for(i=0; i<stanza_len; i++){ | 127 | for(i=0; i<stanza_len; i++){ |
128 | c=fgetc(f); | 128 | c=fgetc(f); |
129 | /* Strip leading whitespace */ | ||
130 | if(i==0) for(c; isspace(c); c=fgetc(f)); | ||
129 | /* nope, read to the end of the line */ | 131 | /* nope, read to the end of the line */ |
130 | if(c!=stanza[i]) { | 132 | if(c!=stanza[i]) { |
131 | GOBBLE_TO(f, c, '\n'); | 133 | GOBBLE_TO(f, c, '\n'); |
@@ -135,6 +137,8 @@ static np_arg_list* read_defaults(FILE *f, const char *stanza){ | |||
135 | /* if it matched up to here and the next char is ']'... */ | 137 | /* if it matched up to here and the next char is ']'... */ |
136 | if(i==stanza_len){ | 138 | if(i==stanza_len){ |
137 | c=fgetc(f); | 139 | c=fgetc(f); |
140 | /* Strip trailing whitespace */ | ||
141 | for(c; isspace(c); c=fgetc(f)); | ||
138 | if(c==']') stanzastate=RIGHTSTANZA; | 142 | if(c==']') stanzastate=RIGHTSTANZA; |
139 | } | 143 | } |
140 | break; | 144 | break; |
@@ -223,7 +227,7 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
223 | /* calculate the length of "--foo" */ | 227 | /* calculate the length of "--foo" */ |
224 | opt_len=1+optend-optptr; | 228 | opt_len=1+optend-optptr; |
225 | /* 1-character params needs only one dash */ | 229 | /* 1-character params needs only one dash */ |
226 | if (opt_len==1) | 230 | if(opt_len==1) |
227 | cfg_len=1+(opt_len); | 231 | cfg_len=1+(opt_len); |
228 | else | 232 | else |
229 | cfg_len=2+(opt_len); | 233 | cfg_len=2+(opt_len); |
@@ -234,7 +238,7 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
234 | cfg_len+=1+val_len; | 238 | cfg_len+=1+val_len; |
235 | } | 239 | } |
236 | /* if valptr==valend then we have "=" but no "bar" */ | 240 | /* if valptr==valend then we have "=" but no "bar" */ |
237 | else if (valptr==lineend) { | 241 | else if(valptr==lineend) { |
238 | equals=1; | 242 | equals=1; |
239 | cfg_len+=1; | 243 | cfg_len+=1; |
240 | } | 244 | } |
@@ -248,7 +252,7 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
248 | read_pos=0; | 252 | read_pos=0; |
249 | optnew->arg=(char *)malloc(cfg_len+1); | 253 | optnew->arg=(char *)malloc(cfg_len+1); |
250 | /* 1-character params needs only one dash */ | 254 | /* 1-character params needs only one dash */ |
251 | if (opt_len==1) { | 255 | if(opt_len==1) { |
252 | strncpy(&optnew->arg[read_pos], "-", 1); | 256 | strncpy(&optnew->arg[read_pos], "-", 1); |
253 | read_pos+=1; | 257 | read_pos+=1; |
254 | } else { | 258 | } else { |
@@ -263,10 +267,10 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
263 | optnew->arg[read_pos]='\0'; | 267 | optnew->arg[read_pos]='\0'; |
264 | 268 | ||
265 | /* ...and put that to the end of the list */ | 269 | /* ...and put that to the end of the list */ |
266 | if (*optlst==NULL) { | 270 | if(*optlst==NULL) { |
267 | *optlst=optnew; | 271 | *optlst=optnew; |
268 | } else { | 272 | } else { |
269 | while (opttmp->next!=NULL) { | 273 | while(opttmp->next!=NULL) { |
270 | opttmp=opttmp->next; | 274 | opttmp=opttmp->next; |
271 | } | 275 | } |
272 | opttmp->next = optnew; | 276 | opttmp->next = optnew; |