[MPlayer-dev-eng] [PATCH 2/3] Use mp_dir_join instead of sprintf.

Clément Bœsch ubitux at gmail.com
Sun Jan 23 20:46:27 CET 2011


This avoid a potential heap overflow and create a cleaner path: no
double "//" in the path for example, or event "\\/" on DOS-like systems.
---
 sub/subreader.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/sub/subreader.c b/sub/subreader.c
index 4fc69a1..bf100c3 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -2012,21 +2012,23 @@ static void append_dir_subtitles(struct sub_list *slist, const char *path,
                 }
 
                 if (prio) {
+                    char *subpath;
                     prio += prio;
 #ifdef CONFIG_ICONV
                     if (i < 3){ // prefer UTF-8 coded
                         prio++;
                     }
 #endif
-                    sprintf(tmpresult, "%s/%s", path, de->d_name);
-                    // fprintf(stderr, "%s priority %d\n", tmpresult, prio);
-                    if ((f = fopen(tmpresult, "rt"))) {
+                    subpath = mp_dir_join(path, de->d_name);
+                    // fprintf(stderr, "%s priority %d\n", subpath, prio);
+                    if ((f = fopen(subpath, "rt"))) {
                         struct subfn *sub = &slist->subs[slist->sid++];
 
                         fclose(f);
                         sub->priority = prio;
-                        sub->fname    = strdup(tmpresult);
-                    }
+                        sub->fname    = subpath;
+                    } else
+                        free(subpath);
                 }
 
             }
-- 
1.7.3.5



More information about the MPlayer-dev-eng mailing list