[MPlayer-dev-eng] [PATCH] suboption escaping

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Oct 19 12:50:05 CEST 2005


Hi,
On Fri, Aug 19, 2005 at 12:22:00PM +0200, Reimar Döffinger wrote:
> You can be sure I tested this extensively, on all the systems I have
> (MacOSX not among those though) and it does work fine for me!
> Can you give me any hints?

Ok, I think I found the bug, and I'd like to say I'm not the only one to
blame here (I guess I should have check the man page instead of just
looking at our implementation of strlcpy). Please test the attached patch.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: m_option.c
===================================================================
RCS file: /cvsroot/mplayer/main/m_option.c,v
retrieving revision 1.42
diff -u -r1.42 m_option.c
--- m_option.c	13 Oct 2005 18:33:56 -0000	1.42
+++ m_option.c	19 Oct 2005 10:49:19 -0000
@@ -886,7 +886,7 @@
       int optlen = strcspn(p, ":=");
       /* clear out */
       subopt[0] = subparam[0] = 0;
-      strlcpy(subopt, p, optlen);
+      strlcpy(subopt, p, optlen + 1);
       p = &p[optlen];
       if (p[0] == '=') {
         sscanf_ret = 2;
@@ -894,7 +894,7 @@
         if (p[0] == '"') {
           p = &p[1];
           optlen = strcspn(p, "\"");
-          strlcpy(subparam, p, optlen);
+          strlcpy(subparam, p, optlen + 1);
           p = &p[optlen];
           if (p[0] != '"') {
             mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Terminating '\"' missing for '%s'\n", subopt);
@@ -909,11 +909,11 @@
             return M_OPT_INVALID;
           }
           p = &p[1];
-          strlcpy(subparam, p, optlen);
+          strlcpy(subparam, p, optlen + 1);
           p = &p[optlen];
         } else {
           optlen = strcspn(p, ":");
-          strlcpy(subparam, p, optlen);
+          strlcpy(subparam, p, optlen + 1);
           p = &p[optlen];
         }
       }
Index: osdep/strl.c
===================================================================
RCS file: /cvsroot/mplayer/main/osdep/strl.c,v
retrieving revision 1.2
diff -u -r1.2 strl.c
--- osdep/strl.c	6 Apr 2005 11:57:10 -0000	1.2
+++ osdep/strl.c	19 Oct 2005 10:49:19 -0000
@@ -10,6 +10,7 @@
 unsigned int strlcpy (char *dest, const char *src, unsigned int size)
 {
 	register unsigned int i;
+	size--; // termination 0 counts too
 
 	for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
 		dest[i] = src[i];
@@ -25,6 +26,7 @@
 {
 #if 0
 	register unsigned int i, j;
+	size--; // termination 0 counts too
 
 	for(i=0; size > 0 && dest[i] != '\0'; size--, i++);
 	for(j=0; size > 0 && src[j] != '\0'; size--, i++, j++)
@@ -35,6 +37,7 @@
 #else
 	register char *d = dest;
 	register const char *s = src;
+	size--; // termination 0 counts too
 
 	for (; size > 0 && *d != '\0'; size--, d++);
 	for (; size > 0 && *s != '\0'; size--, d++, s++)


More information about the MPlayer-dev-eng mailing list