diff options
| author | markw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-23 23:16:20 +0000 |
|---|---|---|
| committer | markw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-23 23:16:20 +0000 |
| commit | 9fdce716fc69295019478dcff920628237dcb822 (patch) | |
| tree | 1268e2463342a50f331ca9010738fe49c82d1ea6 /util-linux | |
| parent | fde25fd589df106e609900b69ff93b0c3239f85c (diff) | |
| download | busybox-w32-9fdce716fc69295019478dcff920628237dcb822.tar.gz busybox-w32-9fdce716fc69295019478dcff920628237dcb822.tar.bz2 busybox-w32-9fdce716fc69295019478dcff920628237dcb822.zip | |
Applied patch from Larry Doolittle to remove some strlen calls, and add one
paranoia check to avoid buffer underrun. Saves 120 text bytes.
git-svn-id: svn://busybox.net/trunk/busybox@2417 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/getopt.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index b74dd65a1..95ecba6e6 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
| @@ -243,20 +243,23 @@ void add_longopt(const char *name,int has_arg) | |||
| 243 | */ | 243 | */ |
| 244 | void add_long_options(char *options) | 244 | void add_long_options(char *options) |
| 245 | { | 245 | { |
| 246 | int arg_opt; | 246 | int arg_opt, tlen; |
| 247 | char *tokptr=strtok(options,", \t\n"); | 247 | char *tokptr=strtok(options,", \t\n"); |
| 248 | while (tokptr) { | 248 | while (tokptr) { |
| 249 | arg_opt=no_argument; | 249 | arg_opt=no_argument; |
| 250 | if (strlen(tokptr) > 0) { | 250 | tlen=strlen(tokptr); |
| 251 | if (tokptr[strlen(tokptr)-1] == ':') { | 251 | if (tlen > 0) { |
| 252 | if (tokptr[strlen(tokptr)-2] == ':') { | 252 | if (tokptr[tlen-1] == ':') { |
| 253 | tokptr[strlen(tokptr)-2]='\0'; | 253 | if (tlen > 1 && tokptr[tlen-2] == ':') { |
| 254 | tokptr[tlen-2]='\0'; | ||
| 255 | tlen -= 2; | ||
| 254 | arg_opt=optional_argument; | 256 | arg_opt=optional_argument; |
| 255 | } else { | 257 | } else { |
| 256 | tokptr[strlen(tokptr)-1]='\0'; | 258 | tokptr[tlen-1]='\0'; |
| 259 | tlen -= 1; | ||
| 257 | arg_opt=required_argument; | 260 | arg_opt=required_argument; |
| 258 | } | 261 | } |
| 259 | if (strlen(tokptr) == 0) | 262 | if (tlen == 0) |
| 260 | error_msg("empty long option after -l or --long argument"); | 263 | error_msg("empty long option after -l or --long argument"); |
| 261 | } | 264 | } |
| 262 | add_longopt(tokptr,arg_opt); | 265 | add_longopt(tokptr,arg_opt); |
