[vlc-commits] darwin/dirs: Fix stack-use-after-scope bug

Marvin Scholz git at videolan.org
Wed Oct 4 01:01:56 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Oct  4 01:00:56 2017 +0200| [3acf45b1477f989e271dc0d234d5d9256bc0f758] | committer: Marvin Scholz

darwin/dirs: Fix stack-use-after-scope bug

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3acf45b1477f989e271dc0d234d5d9256bc0f758
---

 src/darwin/dirs.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/darwin/dirs.c b/src/darwin/dirs.c
index 32acc4e0dc..f79990d541 100644
--- a/src/darwin/dirs.c
+++ b/src/darwin/dirs.c
@@ -138,24 +138,30 @@ static char *getAppDependentDir(vlc_userdir_t type)
     }
 
     // Default fallback
-    const char *name = "org.videolan.vlc";
+    const char *fallback = strdup("org.videolan.vlc");
+    char *name = NULL;
 
     CFBundleRef mainBundle = CFBundleGetMainBundle();
     if (mainBundle) {
         CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle);
         if (identifierAsNS) {
-            char identifier[256];
-            Boolean ret = CFStringGetCString(identifierAsNS, identifier, sizeof(identifier), kCFStringEncodingUTF8);
-            if (ret)
-                name = identifier;
+            CFIndex len = CFStringGetLength(identifierAsNS);
+            CFIndex size = CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8);
+            char *identifier = calloc(len + 1, sizeof(char));
+            if (identifier != NULL) {
+                Boolean ret = CFStringGetCString(identifierAsNS, identifier, size, kCFStringEncodingUTF8);
+                if (ret)
+                    name = identifier;
+            }
         }
     }
 
     char *psz_parent = config_GetHomeDir ();
     char *psz_dir;
-    if ( asprintf( &psz_dir, psz_path, psz_parent, name) == -1 )
+    if ( asprintf( &psz_dir, psz_path, psz_parent, (name) ? name : fallback) == -1 )
         psz_dir = NULL;
     free(psz_parent);
+    free(name);
 
     return psz_dir;
 }



More information about the vlc-commits mailing list