From: Paul Durrant Date: Mon, 20 Sep 2021 08:26:29 +0000 (+0100) Subject: Fix issues raised by CodeQL (part 2) X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=773a3a74f499d26be51b02bfe7ae93333d7daef9;p=pvdrivers%2Fwin%2Fxenbus.git Fix issues raised by CodeQL (part 2) 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 Signed-off-by: Paul Durrant --- diff --git a/src/xenfilt/emulated.c b/src/xenfilt/emulated.c index 0c2c087..83b2070 100644 --- a/src/xenfilt/emulated.c +++ b/src/xenfilt/emulated.c @@ -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;