Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by christos in t...



details:   https://anonhg.NetBSD.org/src/rev/fb92f91fa631
branches:  netbsd-8
changeset: 851366:fb92f91fa631
user:      snj <snj%NetBSD.org@localhost>
date:      Mon Feb 12 04:05:07 2018 +0000

description:
Pull up following revision(s) (requested by christos in ticket #545):
        sbin/gpt/backup.c: 1.17-1.18
        sbin/gpt/biosboot.c: 1.29-1.30
        sbin/gpt/gpt.c: 1.71-1.73
        sbin/gpt/gpt.h: 1.36
        sbin/gpt/restore.c: 1.17
        sbin/gpt/show.c: 1.40-1.41
        sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.

diffstat:

 sbin/gpt/backup.c             |   5 +++--
 sbin/gpt/biosboot.c           |   8 +++++---
 sbin/gpt/gpt.c                |  30 ++++++++++++++++++++++--------
 sbin/gpt/gpt.h                |   2 +-
 sbin/gpt/restore.c            |   4 ++--
 sbin/gpt/show.c               |  14 +++++++++-----
 sys/dev/dkwedge/dkwedge_gpt.c |   7 ++++---
 7 files changed, 46 insertions(+), 24 deletions(-)

diffs (234 lines):

diff -r 3322442bfdd8 -r fb92f91fa631 sbin/gpt/backup.c
--- a/sbin/gpt/backup.c Mon Feb 12 00:57:48 2018 +0000
+++ b/sbin/gpt/backup.c Mon Feb 12 04:05:07 2018 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: backup.c,v 1.16 2015/12/03 21:40:32 christos Exp $");
+__RCSID("$NetBSD: backup.c,v 1.16.8.1 2018/02/12 04:05:07 snj Exp $");
 #endif
 
 #include <sys/bootblock.h>
@@ -231,7 +231,8 @@
                PROP_ERR(propnum);
                rc = prop_dictionary_set(gpt_dict, "attributes", propnum);
                PROP_ERR(rc);
-               utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
+               utf16_to_utf8(ent->ent_name, __arraycount(ent->ent_name),
+                   utfbuf, __arraycount(utfbuf));
                if (utfbuf[0] != '\0') {
                        propstr = prop_string_create_cstring((char *)utfbuf);
                        PROP_ERR(propstr);
diff -r 3322442bfdd8 -r fb92f91fa631 sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c       Mon Feb 12 00:57:48 2018 +0000
+++ b/sbin/gpt/biosboot.c       Mon Feb 12 04:05:07 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosboot.c,v 1.27.4.1 2017/07/05 20:07:42 snj Exp $ */
+/*     $NetBSD: biosboot.c,v 1.27.4.2 2018/02/12 04:05:07 snj Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.27.4.1 2017/07/05 20:07:42 snj Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.27.4.2 2018/02/12 04:05:07 snj Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -219,7 +219,9 @@
                        break;
 
                if (label != NULL) {
-                       utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
+                       utf16_to_utf8(ent->ent_name,
+                           __arraycount(ent->ent_name), utfbuf,
+                           __arraycount(utfbuf));
                        if (strcmp((char *)label, (char *)utfbuf) == 0)
                                break;
                }
diff -r 3322442bfdd8 -r fb92f91fa631 sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c    Mon Feb 12 00:57:48 2018 +0000
+++ b/sbin/gpt/gpt.c    Mon Feb 12 04:05:07 2018 +0000
@@ -35,7 +35,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.70 2017/02/16 03:32:17 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.70.4.1 2018/02/12 04:05:07 snj Exp $");
 #endif
 
 #include <sys/param.h>
@@ -121,16 +121,22 @@
        return crc ^ ~0U;
 }
 
+/*
+ * Produce a NUL-terminated utf-8 string from the non-NUL-terminated
+ * utf16 string.
+ */
 void
-utf16_to_utf8(const uint16_t *s16, uint8_t *s8, size_t s8len)
+utf16_to_utf8(const uint16_t *s16, size_t s16len, uint8_t *s8, size_t s8len)
 {
-       size_t s8idx, s16idx, s16len;
+       size_t s8idx, s16idx;
        uint32_t utfchar;
        unsigned int c;
 
-       s16len = 0;
-       while (s16[s16len++] != 0)
-               continue;
+       for (s16idx = 0; s16idx < s16len; s16idx++)
+               if (s16[s16idx] == 0)
+                       break;
+
+       s16len = s16idx;
        s8idx = s16idx = 0;
        while (s16idx < s16len) {
                utfchar = le16toh(s16[s16idx++]);
@@ -168,6 +174,10 @@
        s8[s8idx] = 0;
 }
 
+/*
+ * Produce a non-NUL-terminated utf-16 string from the NUL-terminated
+ * utf8 string.
+ */
 void
 utf8_to_utf16(const uint8_t *s8, uint16_t *s16, size_t s16len)
 {
@@ -224,11 +234,13 @@
                        } else
                                s16[s16idx++] = htole16((uint16_t)utfchar);
                        if (s16idx == s16len) {
-                               s16[--s16idx] = 0;
                                return;
                        }
                }
        } while (c != 0);
+
+       while (s16idx < s16len)
+               s16[s16idx++] = 0;
 }
 
 void *
@@ -1028,7 +1040,9 @@
 
                ent = gpt_ent_primary(gpt, i);
                if (find->label != NULL) {
-                       utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
+                       utf16_to_utf8(ent->ent_name,
+                           __arraycount(ent->ent_name),
+                           utfbuf, __arraycount(utfbuf));
                        if (strcmp((char *)find->label, (char *)utfbuf) == 0)
                                continue;
                }
diff -r 3322442bfdd8 -r fb92f91fa631 sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h    Mon Feb 12 00:57:48 2018 +0000
+++ b/sbin/gpt/gpt.h    Mon Feb 12 04:05:07 2018 +0000
@@ -99,7 +99,7 @@
 struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int);
 int    gpt_usage(const char *, const struct gpt_cmd *);
 
-void   utf16_to_utf8(const uint16_t *, uint8_t *, size_t);
+void   utf16_to_utf8(const uint16_t *, size_t, uint8_t *, size_t);
 void   utf8_to_utf16(const uint8_t *, uint16_t *, size_t);
 
 #define GPT_FIND "ab:i:L:s:t:"
diff -r 3322442bfdd8 -r fb92f91fa631 sbin/gpt/restore.c
--- a/sbin/gpt/restore.c        Mon Feb 12 00:57:48 2018 +0000
+++ b/sbin/gpt/restore.c        Mon Feb 12 04:05:07 2018 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: restore.c,v 1.16 2015/12/03 02:02:43 christos Exp $");
+__RCSID("$NetBSD: restore.c,v 1.16.8.1 2018/02/12 04:05:07 snj Exp $");
 #endif
 
 #include <sys/types.h>
@@ -178,7 +178,7 @@
        if (propstr != NULL) {
                s = prop_string_cstring_nocopy(propstr);
                utf8_to_utf16((const uint8_t *)s, ent.ent_name,
-                       __arraycount(ent.ent_name));
+                   __arraycount(ent.ent_name));
        }
        propnum = prop_dictionary_get(gpt_dict, "index");
        PROP_ERR(propnum);
diff -r 3322442bfdd8 -r fb92f91fa631 sbin/gpt/show.c
--- a/sbin/gpt/show.c   Mon Feb 12 00:57:48 2018 +0000
+++ b/sbin/gpt/show.c   Mon Feb 12 04:05:07 2018 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: show.c,v 1.39 2016/10/05 03:06:24 kre Exp $");
+__RCSID("$NetBSD: show.c,v 1.39.6.1 2018/02/12 04:05:07 snj Exp $");
 #endif
 
 #include <sys/bootblock.h>
@@ -129,8 +129,9 @@
                printf("GPT part ");
                ent = map_data;
                if (flags & SHOW_LABEL) {
-                       utf16_to_utf8(ent->ent_name, utfbuf,
-                           sizeof(utfbuf));
+                       utf16_to_utf8(ent->ent_name,
+                           __arraycount(ent->ent_name), utfbuf,
+                           __arraycount(utfbuf));
                        b = (char *)utfbuf;
                } else if (flags & SHOW_GUID) {
                        gpt_uuid_snprintf( buf, sizeof(buf), "%d",
@@ -215,7 +216,8 @@
        gpt_uuid_snprintf(s2, sizeof(s1), "%d", ent->ent_guid);
        printf("GUID: %s\n", s2);
 
-       utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
+       utf16_to_utf8(ent->ent_name, __arraycount(ent->ent_name), utfbuf,
+           __arraycount(utfbuf));
        printf("Label: %s\n", (char *)utfbuf);
 
        printf("Attributes: ");
@@ -284,7 +286,9 @@
 #endif
                        putchar('\n');
 
-                       utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
+                       utf16_to_utf8(ent->ent_name,
+                           __arraycount(ent->ent_name), utfbuf,
+                           __arraycount(utfbuf));
                        printf(PFX "Label: %s\n", (char *)utfbuf);
 
                        printf(PFX "Attributes: ");
diff -r 3322442bfdd8 -r fb92f91fa631 sys/dev/dkwedge/dkwedge_gpt.c
--- a/sys/dev/dkwedge/dkwedge_gpt.c     Mon Feb 12 00:57:48 2018 +0000
+++ b/sys/dev/dkwedge/dkwedge_gpt.c     Mon Feb 12 04:05:07 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dkwedge_gpt.c,v 1.18 2017/01/19 00:44:40 maya Exp $    */
+/*     $NetBSD: dkwedge_gpt.c,v 1.18.6.1 2018/02/12 04:05:07 snj Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.18 2017/01/19 00:44:40 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.18.6.1 2018/02/12 04:05:07 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -252,7 +252,8 @@
                else {
                        c = dkw.dkw_wname;
                        r = sizeof(dkw.dkw_wname) - 1;
-                       for (j = 0; ent->ent_name[j] != 0x0000; j++) {
+                       for (j = 0; j < __arraycount(ent->ent_name)
+                           && ent->ent_name[j] != 0x0000; j++) {
                                n = wput_utf8(c, r, le16toh(ent->ent_name[j]));
                                if (n == 0)
                                        break;



Home | Main Index | Thread Index | Old Index