]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
settings: Use dirname(3) correctly
authorTobias Brunner <tobias@strongswan.org>
Fri, 21 Feb 2014 13:58:01 +0000 (14:58 +0100)
committerTobias Brunner <tobias@strongswan.org>
Mon, 24 Feb 2014 11:03:49 +0000 (12:03 +0100)
dirname(3) may return a pointer to a statically allocated buffer.
So freeing the returned value can result to undefined behavior. This was
noticed on FreeBSD where it caused very strange crashes.

It is also not thread-safe, which will be addressed later.

src/libstrongswan/utils/settings.c

index a2c892211de22733ee678584f1bb5e2e701289ac..27a665d16abfce5fc8c3165d4385c010c535812f 100644 (file)
@@ -1302,15 +1302,15 @@ static bool parse_files(linked_list_t *contents, char *file, int level,
        }
        else
        {       /* base relative paths to the directory of the current file */
-               char *dir = strdup(file);
-               dir = dirname(dir);
+               char *path = strdup(file);
+               char *dir = dirname(path);
                if (snprintf(pat, sizeof(pat), "%s/%s", dir, pattern) >= sizeof(pat))
                {
                        DBG1(DBG_LIB, "include pattern too long, ignored");
-                       free(dir);
+                       free(path);
                        return TRUE;
                }
-               free(dir);
+               free(path);
        }
 #ifdef HAVE_GLOB_H
        {