Source-Changes-HG archive

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

[src/netbsd-10]: src/lib/libc/locale Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/32d0ab8b2d9c
branches:  netbsd-10
changeset: 374549:32d0ab8b2d9c
user:      martin <martin%NetBSD.org@localhost>
date:      Tue May 02 17:23:32 2023 +0000

description:
Pull up following revision(s) (requested by mlelstv in ticket #152):

        lib/libc/locale/newlocale.c: revision 1.4

Fix parsing a locale string with multiple components.
Also check for truncation of a long locale string.

diffstat:

 lib/libc/locale/newlocale.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (46 lines):

diff -r f8859a137b7c -r 32d0ab8b2d9c lib/libc/locale/newlocale.c
--- a/lib/libc/locale/newlocale.c       Sun Apr 30 10:58:53 2023 +0000
+++ b/lib/libc/locale/newlocale.c       Tue May 02 17:23:32 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: newlocale.c,v 1.3 2013/09/13 13:13:32 joerg Exp $ */
+/* $NetBSD: newlocale.c,v 1.3.38.1 2023/05/02 17:23:32 martin Exp $ */
 
 /*-
  * Copyright (c)2008, 2011 Citrus Project,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: newlocale.c,v 1.3 2013/09/13 13:13:32 joerg Exp $");
+__RCSID("$NetBSD: newlocale.c,v 1.3.38.1 2023/05/02 17:23:32 martin Exp $");
 
 #include "namespace.h"
 #include <assert.h>
@@ -57,7 +57,10 @@ newlocale(int mask, const char *name, lo
        if (src == NULL)
                src = _current_locale();
        memcpy(dst, src, sizeof(*src));
-       strlcpy(&head[0], name, sizeof(head));
+       if (strlcpy(&head[0], name, sizeof(head)) >= sizeof(head)) {
+               free(dst);
+               return (locale_t)NULL;
+       }
        tokens[0] = (const char *)&head[0];
        tail = strchr(tokens[0], '/');
        if (tail == NULL) {
@@ -77,6 +80,7 @@ newlocale(int mask, const char *name, lo
                }
                if (howmany-- > 0) {
                        for (i = 1; i < howmany; ++i) {
+                               *tail++ = '\0';
                                tokens[i] = (const char *)tail;
                                tail = strchr(tokens[i], '/');
                                if (tail == NULL) {
@@ -84,6 +88,7 @@ newlocale(int mask, const char *name, lo
                                        return NULL;
                                }
                        }
+                       *tail++ = '\0';
                        tokens[howmany] = tail;
                        tail = strchr(tokens[howmany], '/');
                        if (tail != NULL) {



Home | Main Index | Thread Index | Old Index