]> xenbits.xensource.com Git - pvdrivers/win/xenbus.git/commitdiff
Fix issues raised by CodeQL (part 2)
authorPaul Durrant <pdurrant@amazon.com>
Mon, 20 Sep 2021 08:26:29 +0000 (09:26 +0100)
committerPaul Durrant <pdurrant@amazon.com>
Mon, 20 Sep 2021 08:28:36 +0000 (09:28 +0100)
Swap strtol() for strtoul() in emulated.c (since we're not interested in
negative values anyway) and then check the returned value *before* checking
the end pointer.

Reported-by: Owen Smith <owen.smith@citrix.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
src/xenfilt/emulated.c

index 0c2c0876187519e2569fe13d53c7592252b7655c..83b20704a642eb0dbdfdf85d13441bdddda509a1 100644 (file)
@@ -171,30 +171,30 @@ EmulatedSetObjectDiskData(
     if (Type != XENFILT_EMULATED_OBJECT_TYPE_IDE)
         goto fail1;
 
-    Controller = strtol(InstanceID, &End, 10);
+    Controller = strtoul(InstanceID, &End, 10);
 
     status = STATUS_INVALID_PARAMETER;
-    if (*End != '.' || Controller > 1)
+    if (Controller > 1 || *End != '.')
         goto fail2;
 
     End++;
 
-    Target = strtol(End, &End, 10);
+    Target = strtoul(End, &End, 10);
 
     status = STATUS_INVALID_PARAMETER;
-    if (*End != '.' || Target > 1)
+    if (Target > 1 || *End != '.')
         goto fail3;
 
     End++;
 
-    Lun = strtol(End, &End, 10);
-
-    status = STATUS_INVALID_PARAMETER;
-    if (*End != '\0')
-        goto fail4;
+    Lun = strtoul(End, &End, 10);
 
     status = STATUS_NOT_SUPPORTED;
     if (Lun != 0)
+        goto fail4;
+
+    status = STATUS_INVALID_PARAMETER;
+    if (*End != '\0')
         goto fail5;
 
     EmulatedObject->Data.Disk.Index = Controller << 1 | Target;