changeset 10624:cdfd4a43c406

I've juste found a bug which prevent to load a file whose name contain a quote ('). The menu simply execute a "loadfile '%p'" but when the %p is replaced by the actual value, quotes in it are not escaped ! Moreover, mp_input_parse_cmd contain some code to unescape strings but this code was placed after the string was copied in his final buffer. So this patch correct this issue. By Aurlien Jacobs
author albeu
date Fri, 15 Aug 2003 18:45:35 +0000
parents abdb28a904c8
children 620cc649f519
files input/input.c libmenu/menu_filesel.c
diffstat 2 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Fri Aug 15 18:02:24 2003 +0000
+++ b/input/input.c	Fri Aug 15 18:45:35 2003 +0000
@@ -601,14 +601,15 @@
 	break;
       } else if(!e) e = ptr+strlen(ptr);
       l = e-start;
-      cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char));
-      strncpy(cmd->args[i].v.s,start,l);
-      cmd->args[i].v.s[l] = '\0';
       ptr2 = start;
        for(e = strchr(ptr2,'\\') ; e ; e = strchr(ptr2,'\\')) {
 	memmove(e,e+1,strlen(e));
 	ptr2 = e + 1;
+        l--;
       }
+      cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char));
+      strncpy(cmd->args[i].v.s,start,l);
+      cmd->args[i].v.s[l] = '\0';
     } break;
     case -1:
       ptr = NULL;
--- a/libmenu/menu_filesel.c	Fri Aug 15 18:02:24 2003 +0000
+++ b/libmenu/menu_filesel.c	Fri Aug 15 18:45:35 2003 +0000
@@ -77,12 +77,22 @@
     int dl = strlen(dir);
     int t1l = p-title; 
     int l = tl - 2 + dl;
-    char*r = malloc(l + 1);
+    char *r, *n, *d = dir;
+    char term = *(p-1);
+
+    do {
+      if (*d == '\\' || *d == term)
+        l++;
+    } while (*d++);
+    r = malloc(l + 1);
+    n = r + t1l;
     memcpy(r,title,t1l);
-    memcpy(r+t1l,dir,dl);
+    do {
+      if (*dir == '\\' || *dir == term)
+        *n++ = '\\';
+    } while ((*n++ = *dir++));
     if(tl - t1l - 2 > 0)
-      memcpy(r+t1l+dl,p+2,tl - t1l - 2);
-    r[l] = '\0';
+      strcpy(n-1,p+2);
     return r;
   } else
     return title;