mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-09 06:10:29 +01:00
core: replace readlink() by glib equivalent in NMDeviceEthernet
Makes the function working for link destinations longer then 127 bytes and fixes a potential bug that the result of readlink() was not zero terminated for long paths. Probably this would be no problem, but better be save. Related: https://bugzilla.redhat.com/attachment.cgi?id=885371 Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
4a22cefc6c
commit
981e33b83b
1 changed files with 6 additions and 9 deletions
|
|
@ -150,18 +150,15 @@ nm_ethernet_error_quark (void)
|
|||
static char *
|
||||
get_link_basename (const char *parent_path, const char *name, GError **error)
|
||||
{
|
||||
char buf[128];
|
||||
char *path;
|
||||
char *link_dest, *path;
|
||||
char *result = NULL;
|
||||
|
||||
path = g_strdup_printf ("%s/%s", parent_path, name);
|
||||
|
||||
memset (buf, 0, sizeof (buf));
|
||||
errno = 0;
|
||||
if (readlink (path, &buf[0], sizeof (buf) - 1) >= 0)
|
||||
result = g_path_get_basename (buf);
|
||||
else
|
||||
g_set_error (error, 0, 1, "failed to read link '%s': %d", path, errno);
|
||||
link_dest = g_file_read_link (path, error);
|
||||
if (link_dest) {
|
||||
result = g_path_get_basename (link_dest);
|
||||
g_free (link_dest);
|
||||
}
|
||||
g_free (path);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue