mirror of
https://github.com/sheumann/hush.git
synced 2025-03-13 00:30:23 +00:00
Replace stack-allocated array with dynamically-allocated data in getopt32().
This commit is contained in:
parent
468751ba5f
commit
3805dfc06e
@ -299,6 +299,7 @@ Special characters:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Code here assumes that 'unsigned' is at least 32 bits wide */
|
/* Code here assumes that 'unsigned' is at least 32 bits wide */
|
||||||
|
/* This is only important if applet_opts is over 16 chars long. */
|
||||||
|
|
||||||
const char *const bb_argv_dash[] = { "-", NULL };
|
const char *const bb_argv_dash[] = { "-", NULL };
|
||||||
|
|
||||||
@ -337,7 +338,7 @@ getopt32(char **argv, const char *applet_opts, ...)
|
|||||||
int argc;
|
int argc;
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
unsigned requires = 0;
|
unsigned requires = 0;
|
||||||
t_complementary complementary[33]; /* last stays zero-filled */
|
t_complementary *complementary = NULL; /* last stays zero-filled */
|
||||||
char first_char;
|
char first_char;
|
||||||
int c;
|
int c;
|
||||||
const unsigned char *s;
|
const unsigned char *s;
|
||||||
@ -365,15 +366,17 @@ getopt32(char **argv, const char *applet_opts, ...)
|
|||||||
|
|
||||||
va_start(p, applet_opts);
|
va_start(p, applet_opts);
|
||||||
|
|
||||||
c = 0;
|
|
||||||
on_off = complementary;
|
|
||||||
memset(on_off, 0, sizeof(complementary));
|
|
||||||
|
|
||||||
/* skip bbox extension */
|
/* skip bbox extension */
|
||||||
first_char = applet_opts[0];
|
first_char = applet_opts[0];
|
||||||
if (first_char == '!')
|
if (first_char == '!')
|
||||||
applet_opts++;
|
applet_opts++;
|
||||||
|
|
||||||
|
c = 0;
|
||||||
|
complementary = calloc(33, sizeof(*complementary));
|
||||||
|
if (complementary == NULL)
|
||||||
|
goto error;
|
||||||
|
on_off = complementary;
|
||||||
|
|
||||||
/* skip GNU extension */
|
/* skip GNU extension */
|
||||||
s = (const unsigned char *)applet_opts;
|
s = (const unsigned char *)applet_opts;
|
||||||
if (*s == '+' || *s == '-')
|
if (*s == '+' || *s == '-')
|
||||||
@ -612,10 +615,12 @@ getopt32(char **argv, const char *applet_opts, ...)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
option_mask32 = flags;
|
option_mask32 = flags;
|
||||||
|
free(complementary);
|
||||||
return flags;
|
return flags;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (first_char != '!')
|
if (first_char != '!')
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
free(complementary);
|
||||||
return (int32_t)-1;
|
return (int32_t)-1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user