summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-04-11 12:46:53 +0200
committerThomas Haller <thaller@redhat.com>2014-05-02 14:21:53 +0200
commit981e33b83b57377d04fa6caa50a4434c59fb9285 (patch)
tree1f3c9aabfab0f57af1097e1a2a912a265892d8e2
parent4a22cefc6cff7d5beb351fc72095738bc8cd844e (diff)
downloadNetworkManager-981e33b83b57377d04fa6caa50a4434c59fb9285.tar.gz
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>
-rw-r--r--src/devices/nm-device-ethernet.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 79e9086fcd..e9937e4b56 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -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;
}