From c28f8256ca105da2d3b1f47a3a348fa47e7d89c6 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Wed, 18 Jul 2012 10:37:38 +0100 Subject: storage: check that the string isn't empty before splitting If the string was non-NULL but empty (str="\0"), the following \0 assignment would write to str[-1] and thus cause memory corruption. On PPC and MIPS, this was causing crashes in glibc. --- src/storage.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/storage.c') diff --git a/src/storage.c b/src/storage.c index 47bd0cbc..20766a34 100644 --- a/src/storage.c +++ b/src/storage.c @@ -212,7 +212,11 @@ gchar **connman_storage_get_services() closedir(dir); str = g_string_free(result, FALSE); - if (str) { + if (str && str[0] != '\0') { + /* + * Remove the trailing separator so that services doesn't end up + * with an empty element. + */ str[strlen(str) - 1] = '\0'; services = g_strsplit(str, "/", -1); } -- cgit v1.2.3