if (*val == LONG_MAX && errno == ERANGE)
return 1;
- if (kilo)
- *val *= get_mult_bytes(str[len - 1], data);
- else
+ if (kilo) {
+ const char *p;
+ /*
+ * if the last char is 'b' or 'B', the user likely used
+ * "1gb" instead of just "1g". If the second to last is also
+ * a letter, adjust.
+ */
+ p = str + len - 1;
+ if ((*p == 'b' || *p == 'B') && isalpha(*(p - 1)))
+ --p;
+
+ *val *= get_mult_bytes(*p, data);
+ } else
*val *= get_mult_time(str[len - 1]);
return 0;
ssize_t nchr = OPT_LEN_MAX;
size_t envlen;
+ if (strlen(in) + 1 > OPT_LEN_MAX) {
+ fprintf(stderr, "OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
+ return NULL;
+ }
+
in[OPT_LEN_MAX] = '\0';
strncpy(in, opt, OPT_LEN_MAX);
char *post, *tmp;
tmp = option_dup_subs(opt);
+ if (!tmp)
+ return 1;
o = get_option(tmp, options, &post);
if (!o) {