mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
virPCIDeviceReadID: Fix use of 'virFileReadAll'
Use 'virFileReadAllQuiet' since the function doesn't want to report errors on other code paths. The function also assumed that the file which it reads always 7 bytes isn't true at least in the test suite. This didn't cause a problem because the test data had strings 6 bytes long so it didn't cause a write beyond the end of the buffer. Clear the newline by using strchrnul instead to find it rather than assuming where it is. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
1 parent
59684e9cc1
commit
4fc09da299
1 file changed
+5
-4
+5
-4
@@ -1760,19 +1760,20 @@ virPCIDeviceReadID(virPCIDevice *dev, const char *id_name)
|
||||
{
|
||||
g_autofree char *path = NULL;
|
||||
g_autofree char *id_str = NULL;
|
||||
int len;
|
||||
|
||||
path = virPCIFile(dev->name, id_name);
|
||||
|
||||
/* ID string is '0xNNNN\n' ... i.e. 7 bytes */
|
||||
if (virFileReadAll(path, 7, &id_str) < 0)
|
||||
if ((len = virFileReadAllQuiet(path, 7, &id_str)) < 0)
|
||||
return NULL;
|
||||
|
||||
/* Check for 0x suffix */
|
||||
/* Check for 0x prefix */
|
||||
if (id_str[0] != '0' || id_str[1] != 'x')
|
||||
return NULL;
|
||||
|
||||
/* Chop off the newline; we know the string is 7 bytes */
|
||||
id_str[6] = '\0';
|
||||
/* Chop off the newline */
|
||||
virStringTrimOptionalNewline(id_str);
|
||||
|
||||
return g_steal_pointer(&id_str);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user