/* Host file transfer support for gdbserver.
- Copyright (C) 2007-2016 Free Software Foundation, Inc.
+ Copyright (C) 2007-2018 Free Software Foundation, Inc.
Contributed by CodeSourcery.
require_int (char **pp, int *value)
{
char *p;
- int count;
+ int count, firstdigit;
p = *pp;
*value = 0;
count = 0;
+ firstdigit = -1;
while (*p && *p != ',')
{
int nib;
- /* Don't allow overflow. */
- if (count >= 7)
+ if (safe_fromhex (p[0], &nib))
return -1;
- if (safe_fromhex (p[0], &nib))
+ if (firstdigit == -1)
+ firstdigit = nib;
+
+ /* Don't allow overflow. */
+ if (count >= 8 || (count == 7 && firstdigit >= 0x8))
return -1;
+
*value = *value * 16 + nib;
p++;
count++;