Browse code

ffserver: Fix off by 1 error in path

Code suggested by ubitux

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 617f0c65e1bac8983a5b6521818c1b9b57f0804b)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2017/10/23 00:11:20
Showing 1 changed files
... ...
@@ -476,7 +476,7 @@ static int compute_datarate(DataRateData *drd, int64_t count)
476 476
 static void start_children(FFServerStream *feed)
477 477
 {
478 478
     char *pathname;
479
-    char *slash;
479
+    char *dirname, *prog;
480 480
     int i;
481 481
     size_t cmd_length;
482 482
 
... ...
@@ -495,22 +495,18 @@ static void start_children(FFServerStream *feed)
495 495
         return;
496 496
     }
497 497
 
498
-    slash = strrchr(my_program_name, '/');
499
-    if (!slash) {
500
-        pathname = av_mallocz(sizeof("ffmpeg"));
501
-    } else {
502
-        pathname = av_mallocz(slash - my_program_name + sizeof("ffmpeg"));
503
-        if (pathname != NULL) {
504
-            memcpy(pathname, my_program_name, slash - my_program_name);
505
-        }
506
-    }
507
-    if (!pathname) {
498
+   /* use "ffmpeg" in the path of current program. Ignore user provided path */
499
+    prog = av_strdup(my_program_name);
500
+    if (prog) {
501
+        dirname = av_dirname(prog);
502
+        pathname = *dirname ? av_asprintf("%s/%s", dirname, "ffmpeg")
503
+                            : av_asprintf("ffmpeg");
504
+        av_free(prog);
505
+    }
506
+    if (!prog || !pathname) {
508 507
         http_log("Could not allocate memory for children cmd line\n");
509 508
         return;
510 509
     }
511
-   /* use "ffmpeg" in the path of current program. Ignore user provided path */
512
-
513
-    strcat(pathname, "ffmpeg");
514 510
 
515 511
     for (; feed; feed = feed->next) {
516 512