1
1

Sync with gnulib 6ed53f13bc39d9a0252549e98a2a59441fb2351f.

lib/strutil/xstrtol.c: prohibit monstrosities like "1bB".

Problem reported by Young Mo Kang in: http://bugs.gnu.org/23388.

(xstrtoumax): Allow trailing second suffixes like "B" only if the first
suffix needs a base.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2016-05-01 08:44:00 +03:00
родитель abbfde35b2
Коммит bdb81cd482

Просмотреть файл

@ -142,30 +142,47 @@ xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val, const char *va
base = 1024; base = 1024;
if (strchr (valid_suffixes, '0') != NULL) switch (**p)
{ {
/* The "valid suffix" '0' is a special flag meaning that case 'E':
an optional second suffix is allowed, which can change case 'G':
the base. A suffix "B" (e.g. "100MB") stands for a power case 'g':
of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for case 'k':
a power of 1024. If no suffix (e.g. "100M"), assume case 'K':
power-of-1024. */ case 'M':
case 'm':
switch (p[0][1]) case 'P':
case 'T':
case 't':
case 'Y':
case 'Z':
if (strchr (valid_suffixes, '0') != NULL)
{ {
case 'i': /* The "valid suffix" '0' is a special flag meaning that
if (p[0][2] == 'B') an optional second suffix is allowed, which can change
suffixes += 2; the base. A suffix "B" (e.g. "100MB") stands for a power
break; of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for
a power of 1024. If no suffix (e.g. "100M"), assume
power-of-1024. */
case 'B': switch (p[0][1])
case 'D': /* 'D' is obsolescent */ {
base = 1000; case 'i':
suffixes++; if (p[0][2] == 'B')
break; suffixes += 2;
default: break;
break;
case 'B':
case 'D': /* 'D' is obsolescent */
base = 1000;
suffixes++;
break;
default:
break;
}
} }
default:
break;
} }
switch (**p) switch (**p)
@ -175,6 +192,9 @@ xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val, const char *va
break; break;
case 'B': case 'B':
/* This obsolescent first suffix is distinct from the 'B'
second suffix above. E.g., 'tar -L 1000B' means change
the tape after writing 1000 KiB of data. */
overflow = bkm_scale (&tmp, 1024); overflow = bkm_scale (&tmp, 1024);
break; break;