Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/700be66b2f6d
branches:  netbsd-8
changeset: 319049:700be66b2f6d
user:      martin <martin%NetBSD.org@localhost>
date:      Mon May 14 19:17:39 2018 +0000
description:
Pull up following revision(s) (requested by maya in ticket #822):

        lib/libc/string/stresep.c: revision 1.4
        tests/lib/libc/string/t_stresep.c: revision 1.4

PR/52499: Justin: stresep uses memmove with of-by-one length
Add test from PR/52499

diffstat:

 lib/libc/string/stresep.c         |  16 ++++++++++------
 tests/lib/libc/string/t_stresep.c |   8 +++++++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diffs (78 lines):

diff -r dae0eff05edc -r 700be66b2f6d lib/libc/string/stresep.c
--- a/lib/libc/string/stresep.c Mon May 14 19:11:21 2018 +0000
+++ b/lib/libc/string/stresep.c Mon May 14 19:17:39 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stresep.c,v 1.3 2017/02/12 17:19:00 maya Exp $ */
+/*     $NetBSD: stresep.c,v 1.3.4.1 2018/05/14 19:17:39 martin 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.3.4.1 2018/05/14 19:17:39 martin 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');
        }
 }
diff -r dae0eff05edc -r 700be66b2f6d tests/lib/libc/string/t_stresep.c
--- a/tests/lib/libc/string/t_stresep.c Mon May 14 19:11:21 2018 +0000
+++ b/tests/lib/libc/string/t_stresep.c Mon May 14 19:17:39 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_stresep.c,v 1.3 2013/02/15 23:56:32 christos Exp $ */
+/*     $NetBSD: t_stresep.c,v 1.3.22.1 2018/05/14 19:17:39 martin Exp $ */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -61,6 +61,12 @@
        expect("bar  foo");
        expect("   baz");
        expect("bar  ");
+
+       char brkstr2[] = "aa bb cc\\ \\ \\ \\ dd-";
+       q = brkstr2;
+       expect("aa");
+       expect("bb");
+       expect("cc    dd-");
 }
 
 ATF_TP_ADD_TCS(tp)



Home | Main Index | Thread Index | Old Index