Module Name:    src
Committed By:   nia
Date:           Fri Oct 29 10:11:57 UTC 2021

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

Log Message:
wcsdup(3): use reallocarr to catch integer overflow


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/string/wcsdup.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/wcsdup.c
diff -u src/lib/libc/string/wcsdup.c:1.3 src/lib/libc/string/wcsdup.c:1.4
--- src/lib/libc/string/wcsdup.c:1.3	Mon May 26 13:17:48 2008
+++ src/lib/libc/string/wcsdup.c	Fri Oct 29 10:11:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $	*/
+/*	$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 nia Exp $	*/
 
 /*
  * Copyright (C) 2006 Aleksey Cheusov
@@ -14,7 +14,7 @@
 #include <sys/cdefs.h>
 
 #if defined(LIBC_SCCS) && !defined(lint) 
-__RCSID("$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $"); 
+__RCSID("$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 nia Exp $"); 
 #endif /* LIBC_SCCS and not lint */ 
 
 #include "namespace.h"
@@ -33,9 +33,9 @@ wcsdup(const wchar_t *str)
 	_DIAGASSERT(str != NULL);
 
 	len = wcslen(str) + 1;
-	copy = malloc(len * sizeof (wchar_t));
 
-	if (!copy)
+	copy = NULL;
+	if (reallocarr(&copy, len, sizeof(wchar_t)) != 0)
 		return NULL;
 
 	return wmemcpy(copy, str, len);

Reply via email to