Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/locale correct use of strlcpy (really need to enfor...



details:   https://anonhg.NetBSD.org/src/rev/2837cbd61562
branches:  trunk
changeset: 534740:2837cbd61562
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Aug 02 08:02:36 2002 +0000

description:
correct use of strlcpy (really need to enforce length, so use memcpy)

diffstat:

 lib/libc/locale/setlocale.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (35 lines):

diff -r c012a5143bf0 -r 2837cbd61562 lib/libc/locale/setlocale.c
--- a/lib/libc/locale/setlocale.c       Fri Aug 02 08:00:36 2002 +0000
+++ b/lib/libc/locale/setlocale.c       Fri Aug 02 08:02:36 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setlocale.c,v 1.38 2002/08/02 07:12:51 tshiozak Exp $  */
+/*     $NetBSD: setlocale.c,v 1.39 2002/08/02 08:02:36 itojun Exp $    */
 
 /*
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)setlocale.c        8.1 (Berkeley) 7/4/93";
 #else
-__RCSID("$NetBSD: setlocale.c,v 1.38 2002/08/02 07:12:51 tshiozak Exp $");
+__RCSID("$NetBSD: setlocale.c,v 1.39 2002/08/02 08:02:36 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -174,11 +174,14 @@
                                len = r - locale > sizeof(new_categories[i]) - 1
                                        ? sizeof(new_categories[i]) - 1
                                        : r - locale;
-                               (void)strlcpy(new_categories[i], locale, len+1);
+                               if (len + 1 > sizeof(new_categories[i]))
+                                       return (NULL);  /* too long */
+                               (void)memcpy(new_categories[i], locale, len);
+                               new_categories[i][len] = '\0';
                                i++;
                                locale = r;
                                while (*locale == '/')
-                                   ++locale;
+                                       ++locale;
                                while (*++r && *r != '/');
                        } while (*locale);
                        while (i < _LC_LAST) {



Home | Main Index | Thread Index | Old Index