Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/string PR/52499: Justin: stresep uses memmove with ...



details:   https://anonhg.NetBSD.org/src/rev/976f16d5342c
branches:  trunk
changeset: 826243:976f16d5342c
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 23 10:27:41 2017 +0000

description:
PR/52499: Justin: stresep uses memmove with of-by-one length

diffstat:

 lib/libc/string/stresep.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (56 lines):

diff -r 30b5d8b26d11 -r 976f16d5342c lib/libc/string/stresep.c
--- a/lib/libc/string/stresep.c Wed Aug 23 09:17:48 2017 +0000
+++ b/lib/libc/string/stresep.c Wed Aug 23 10:27:41 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $ */
+/*     $NetBSD: stresep.c,v 1.4 2017/08/23 10:27:41 christos Exp $     */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)strsep.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $");
+__RCSID("$NetBSD: stresep.c,v 1.4 2017/08/23 10:27:41 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -66,6 +66,7 @@
        char *s;
        const char *spanp;
        int c, sc;
+       size_t l;
        char *tok;
 
        _DIAGASSERT(stringp != NULL);
@@ -73,22 +74,25 @@
 
        if ((s = *stringp) == NULL)
                return NULL;
+       l = strlen(s) + 1;
        for (tok = s;;) {
                c = *s++;
+               l--;
                while (esc != '\0' && c == esc) {
-                       memmove(s - 1, s, strlen(s));
+                       memmove(s - 1, s, l);
                        c = *s++;
+                       l--;
                }
                spanp = delim;
                do {
                        if ((sc = *spanp++) == c) {
-                               if (c == 0)
+                               if (c == '\0')
                                        s = NULL;
                                else
-                                       s[-1] = 0;
+                                       s[-1] = '\0';
                                *stringp = s;
                                return tok;
                        }
-               } while (sc != 0);
+               } while (sc != '\0');
        }
 }



Home | Main Index | Thread Index | Old Index