Skip to content

Commit

Permalink
Sysfs: fixed sysfs_deref_link()
Browse files Browse the repository at this point in the history
The function canonicalize_file_name() is GLIBC-specific, use realpath()
instead, which is available also on MUSL libc.

Also, it leaked memory.
  • Loading branch information
gollux committed Jul 12, 2018
1 parent ffdb5c2 commit f15db37
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/sysfs.c
Expand Up @@ -133,7 +133,8 @@ sysfs_deref_link(struct pci_dev *d, char *link_name)
sysfs_obj_name(d, "", path);
strcat(path, rel_path);

return canonicalize_file_name(path);
// Returns a pointer to malloc'ed memory
return realpath(path, NULL);
}

static int
Expand Down Expand Up @@ -329,7 +330,14 @@ sysfs_fill_info(struct pci_dev *d, int flags)
d->numa_node = sysfs_get_value(d, "numa_node", 0);

if ((flags & PCI_FILL_DT_NODE) && !(d->known_fields & PCI_FILL_DT_NODE))
pci_set_property(d, PCI_FILL_DT_NODE, sysfs_deref_link(d, "of_node"));
{
char *node = sysfs_deref_link(d, "of_node");
if (node)
{
pci_set_property(d, PCI_FILL_DT_NODE, node);
free(node);
}
}

return pci_generic_fill_info(d, flags);
}
Expand Down

0 comments on commit f15db37

Please sign in to comment.