join: Stricter parsing of -o list

This fixes naive parsing that would happily read a giant string
of numbers into fileno provided the first character was correct.
This commit is contained in:
Wolfgang Corcoran-Mathe 2015-06-23 13:42:41 -04:00 committed by sin
parent d0269af73e
commit 47c05f9ff4

17
join.c
View File

@ -335,19 +335,14 @@ makespec(char *s)
int fileno; int fileno;
size_t fldno; size_t fldno;
switch (s[0]) { if (!strcmp(s, "0")) { /* join field must be 0 and nothing else */
case '0': /* join field */
fileno = 0; fileno = 0;
fldno = 0; fldno = 0;
break; } else if ((s[0] == '1' || s[0] == '2') && s[1] == '.') {
case '1': case '2': fileno = s[0] - '0';
if (sscanf(s, "%d.%zu", &fileno, &fldno) != 2) fldno = estrtonum(&s[2], 1, MIN(LLONG_MAX, SIZE_MAX)) - 1;
eprintf("\"%s\": invalid format\n", s); } else {
fldno--; /* ugly */ eprintf("%s: invalid format\n", s);
break;
default:
eprintf("%c: invalid file number (must be 0, 1 or 2)\n", s[0]);
break;
} }
sp = ereallocarray(NULL, INIT, sizeof(struct spec)); sp = ereallocarray(NULL, INIT, sizeof(struct spec));