Fix a coverity-discovered NULL pointer dereference.

*** CID 1372598:  Null pointer dereferences  (FORWARD_NULL)
/lib/libefivar/efivar-dp-parse.c: 3612 in UefiDevicePathLibConvertTextToDeviceNode()
   Dereferencing null pointer "FromText".

When ported from Tiano core, I commented this out with an ifdef. That
was in error because we're supposed to fallback to a filepath when
nothing else patches. Instead, restore the original code, but fix
DevPathFromTextFilePath to cope with the conversion to narrow
strings. Also, fix the off-by-one error in the size of the memory it
allocates.

The off by one error is documented in Tiano core bug
https://bugzilla.tianocore.org/show_bug.cgi?id=441

CID: 1372598
Sponsored by: Netflix
This commit is contained in:
Warner Losh 2017-03-23 02:30:57 +00:00
parent 8af6a2c64e
commit d780e0595c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=315771

View file

@ -3006,7 +3006,6 @@ DevPathFromTextVenMedia (
);
}
#ifndef __FreeBSD__
/**
Converts a text device path node to File device path structure.
@ -3023,6 +3022,7 @@ DevPathFromTextFilePath (
{
FILEPATH_DEVICE_PATH *File;
#ifndef __FreeBSD__
File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
MEDIA_DEVICE_PATH,
MEDIA_FILEPATH_DP,
@ -3030,10 +3030,26 @@ DevPathFromTextFilePath (
);
StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
#else
File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
MEDIA_DEVICE_PATH,
MEDIA_FILEPATH_DP,
(UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) + 1)
);
/*
* Note: We'd have to change the Tianocore header files to fix this
* to not need a cast. Instead we just cast it here. The Interface
* to the user may have issues since this won't be a UCS-2
* string. Also note that in the original code, a NUL wasn't
* allocated for the end of the string, but we copy that below. This
* has been corrected.
*/
StrCpyS ((char *)File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
#endif
return (EFI_DEVICE_PATH_PROTOCOL *) File;
}
#endif
/**
Converts a text device path node to Media protocol device path structure.
@ -3598,7 +3614,6 @@ UefiDevicePathLibConvertTextToDeviceNode (
}
}
#ifndef __FreeBSD__
if (FromText == NULL) {
//
// A file path
@ -3606,9 +3621,6 @@ UefiDevicePathLibConvertTextToDeviceNode (
FromText = DevPathFromTextFilePath;
DeviceNode = FromText (DeviceNodeStr);
} else {
#else
{
#endif
DeviceNode = FromText (ParamStr);
FreePool (ParamStr);
}