[MPlayer-cvslog] r32839 - trunk/sub/subreader.c

cboesch subversion at mplayerhq.hu
Tue Feb 1 20:22:43 CET 2011


Author: cboesch
Date: Tue Feb  1 20:22:43 2011
New Revision: 32839

Log:
Use mp_dir_join instead of sprintf.

This avoids a potential heap overflow and create a cleaner path: no double "//"
in the path for example, or even "\\/" on DOS-like systems.

Modified:
   trunk/sub/subreader.c

Modified: trunk/sub/subreader.c
==============================================================================
--- trunk/sub/subreader.c	Tue Feb  1 20:17:33 2011	(r32838)
+++ trunk/sub/subreader.c	Tue Feb  1 20:22:43 2011	(r32839)
@@ -2012,21 +2012,23 @@ static void append_dir_subtitles(struct 
                 }
 
                 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);
                 }
 
             }


More information about the MPlayer-cvslog mailing list