Improve File I/O overflow detection in gdbserver (PR server/23198)
[deliverable/binutils-gdb.git] / gdb / gdbserver / hostio.c
index d2b5a71bade904343d54349f2e01980b3d822d5e..c621edfef56d514daa4f059c851fe2348f9a1989 100644 (file)
@@ -96,22 +96,27 @@ static int
 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++;
This page took 0.026223 seconds and 4 git commands to generate.