Module Name:    src
Committed By:   martin
Date:           Mon May 14 19:17:39 UTC 2018

Modified Files:
        src/lib/libc/string [netbsd-8]: stresep.c
        src/tests/lib/libc/string [netbsd-8]: t_stresep.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.4.1 src/lib/libc/string/stresep.c
cvs rdiff -u -r1.3 -r1.3.22.1 src/tests/lib/libc/string/t_stresep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/stresep.c
diff -u src/lib/libc/string/stresep.c:1.3 src/lib/libc/string/stresep.c:1.3.4.1
--- src/lib/libc/string/stresep.c:1.3	Sun Feb 12 17:19:00 2017
+++ src/lib/libc/string/stresep.c	Mon May 14 19:17:39 2018
@@ -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 @@ stresep(char **stringp, const char *deli
 	char *s;
 	const char *spanp;
 	int c, sc;
+	size_t l;
 	char *tok;
 
 	_DIAGASSERT(stringp != NULL);
@@ -73,22 +74,25 @@ stresep(char **stringp, const char *deli
 
 	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');
 	}
 }

Index: src/tests/lib/libc/string/t_stresep.c
diff -u src/tests/lib/libc/string/t_stresep.c:1.3 src/tests/lib/libc/string/t_stresep.c:1.3.22.1
--- src/tests/lib/libc/string/t_stresep.c:1.3	Fri Feb 15 23:56:32 2013
+++ src/tests/lib/libc/string/t_stresep.c	Mon May 14 19:17:39 2018
@@ -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 @@ ATF_TC_BODY(stresep_basic, tc)
 	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)

Reply via email to