[hackers] [sbase] join: Stricter parsing of -o list || Wolfgang Corcoran-Mathe

From: <git_AT_suckless.org>
Date: Thu, 25 Jun 2015 13:11:28 +0200 (CEST)

commit 47c05f9ff40ce5180e8b9d689ac4346d1d4bd0bc
Author: Wolfgang Corcoran-Mathe <first.lord.of.teal_AT_gmail.com>
AuthorDate: Tue Jun 23 13:42:41 2015 -0400
Commit: sin <sin_AT_2f30.org>
CommitDate: Thu Jun 25 12:11:23 2015 +0100

    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.

diff --git a/join.c b/join.c
index a013946..1f2fb8c 100644
--- a/join.c
+++ b/join.c
_AT_@ -335,19 +335,14 @@ makespec(char *s)
         int fileno;
         size_t fldno;
 
- switch (s[0]) {
- case '0': /* join field */
+ if (!strcmp(s, "0")) { /* join field must be 0 and nothing else */
                 fileno = 0;
                 fldno = 0;
- break;
- case '1': case '2':
- if (sscanf(s, "%d.%zu", &fileno, &fldno) != 2)
- eprintf("\"%s\": invalid format\n", s);
- fldno--; /* ugly */
- break;
- default:
- eprintf("%c: invalid file number (must be 0, 1 or 2)\n", s[0]);
- break;
+ } else if ((s[0] == '1' || s[0] == '2') && s[1] == '.') {
+ fileno = s[0] - '0';
+ fldno = estrtonum(&s[2], 1, MIN(LLONG_MAX, SIZE_MAX)) - 1;
+ } else {
+ eprintf("%s: invalid format\n", s);
         }
 
         sp = ereallocarray(NULL, INIT, sizeof(struct spec));
Received on Thu Jun 25 2015 - 13:11:28 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 25 2015 - 13:12:15 CEST