[vlc-commits] [Git][videolan/vlc][master] cli: fix SIGSEGV when command has an argument

Jean-Baptiste Kempf gitlab at videolan.org
Fri Jun 11 07:21:20 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
4ce56f45 by KO Myung-Hun at 2021-06-11T06:28:23+00:00
cli: fix SIGSEGV when command has an argument

Co-authored-by: Zhao Zhili <zhilizhao at tencent.com>

- - - - -


1 changed file:

- modules/control/cli/cli.c


Changes:

=====================================
modules/control/cli/cli.c
=====================================
@@ -313,11 +313,14 @@ error:      wordfree(&we);
     for (size_t i = 0; i < we.we_wordc; i++)
         args[i] = we.we_wordv[i];
 #else
+    char *cmd_dup = strdup(cmd);
+    if (unlikely(cmd_dup == NULL))
+        return VLC_ENOMEM;
     /* Split psz_cmd at the first space and make sure that
      * psz_arg is valid */
-    const char *args[] = { cmd, NULL };
+    const char *args[] = { cmd_dup, NULL };
     size_t count = 1;
-    char *arg = strchr(cmd, ' ');
+    char *arg = strchr(cmd_dup, ' ');
 
     if (arg != NULL)
     {
@@ -325,7 +328,7 @@ error:      wordfree(&we);
         arg += strspn(arg, " ");
 
         if (*arg)
-            count++;
+            args[count++] = arg;
     }
 #endif
 
@@ -350,6 +353,8 @@ error:      wordfree(&we);
 #ifdef HAVE_WORDEXP
     free(args);
     wordfree(&we);
+#else
+    free(cmd_dup);
 #endif
     return ret;
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/4ce56f456bdbc298a8a14b5f6368416c8974cfe0

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/4ce56f456bdbc298a8a14b5f6368416c8974cfe0
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list