Module Name:    src
Committed By:   kre
Date:           Wed Mar 25 16:10:17 UTC 2020

Modified Files:
        src/lib/libc/string: strerror.c

Log Message:
Protect against malloc failure corrupting errno, which is not
permitted of these functions.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/strerror.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/strerror.c
diff -u src/lib/libc/string/strerror.c:1.17 src/lib/libc/string/strerror.c:1.18
--- src/lib/libc/string/strerror.c:1.17	Tue Jan 20 18:31:25 2015
+++ src/lib/libc/string/strerror.c	Wed Mar 25 16:10:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror.c,v 1.17 2015/01/20 18:31:25 christos Exp $	*/
+/*	$NetBSD: strerror.c,v 1.18 2020/03/25 16:10:17 kre Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: strerror.c,v 1.17 2015/01/20 18:31:25 christos Exp $");
+__RCSID("$NetBSD: strerror.c,v 1.18 2020/03/25 16:10:17 kre Exp $");
 
 #define __SETLOCALE_SOURCE__
 
@@ -78,7 +78,9 @@ strerror_l(int num, locale_t loc)
 	thr_once(&strerror_once, strerror_setup);
 	buf = thr_getspecific(strerror_key);
 	if (buf == NULL) {
+		error = errno;
 		buf = malloc(NL_TEXTMAX);
+		errno = error;
 		if (buf == NULL) {
 			static char fallback_buf[NL_TEXTMAX];
 			buf = fallback_buf;

Reply via email to