From 3e015d815b3f28bfd874bf8a1697308ef9af2b4c Mon Sep 17 00:00:00 2001 From: Julia Suvorova Date: Thu, 1 Mar 2018 10:08:06 +0300 Subject: use g_path_get_basename instead of basename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit basename(3) and dirname(3) modify their argument and may return pointers to statically allocated memory which may be overwritten by subsequent calls. g_path_get_basename and g_path_get_dirname have no such issues, and therefore more preferable. Signed-off-by: Julia Suvorova Message-Id: <1519888086-4207-1-git-send-email-jusual@mail.ru> Reviewed-by: Marc-André Lureau Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini --- qga/commands-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qga/commands-posix.c') diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ac17d0d6cf..0dc219dbcf 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -808,7 +808,7 @@ static char *get_pci_driver(char const *syspath, int pathlen, Error **errp) len = readlink(dpath, buf, sizeof(buf) - 1); if (len != -1) { buf[len] = 0; - driver = g_strdup(basename(buf)); + driver = g_path_get_basename(buf); } g_free(dpath); g_free(path); @@ -1053,7 +1053,7 @@ static void build_guest_fsinfo_for_device(char const *devpath, } if (!fs->name) { - fs->name = g_strdup(basename(syspath)); + fs->name = g_path_get_basename(syspath); } g_debug(" parse sysfs path '%s'", syspath); -- cgit 1.4.1