Source-Changes-HG archive

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

[src/trunk]: src/sys/net Add the missing add. (Return to the earlier stat...



details:   https://anonhg.NetBSD.org/src/rev/25f7da49529b
branches:  trunk
changeset: 450927:25f7da49529b
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Apr 30 20:56:32 2019 +0000

description:
Add the missing add.     (Return to the earlier state, done differently.)

When dl_print() was converted to use lla_snprintf() the offset to
the LLA in dl_addr.dl_data was forgotten (dl_data contains both
the interface name and the LL addr, we want the latter, not the former).

When there is no data (src_len == 0), still null terminate the output buffer
(provided there is space in it for the \0).

diffstat:

 sys/net/dl_print.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (44 lines):

diff -r 48b7be0159c7 -r 25f7da49529b sys/net/dl_print.c
--- a/sys/net/dl_print.c        Tue Apr 30 20:55:41 2019 +0000
+++ b/sys/net/dl_print.c        Tue Apr 30 20:56:32 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dl_print.c,v 1.5 2019/04/29 19:08:11 christos Exp $    */
+/*     $NetBSD: dl_print.c,v 1.6 2019/04/30 20:56:32 kre Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,10 +29,10 @@
 #include <sys/types.h>
 
 #ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.5 2019/04/29 19:08:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.6 2019/04/30 20:56:32 kre Exp $");
 #include <sys/systm.h>
 #else
-__RCSID("$NetBSD: dl_print.c,v 1.5 2019/04/29 19:08:11 christos Exp $");
+__RCSID("$NetBSD: dl_print.c,v 1.6 2019/04/30 20:56:32 kre Exp $");
 #include <stdio.h>
 static const char hexdigits[] = "0123456789abcdef";
 #endif
@@ -44,8 +44,11 @@
        char *dp;
        const uint8_t *sp, *ep;
 
-       if (src_len == 0 || dst_len < 3)
+       if (src_len == 0 || dst_len < 3) {
+               if (dst_len != 0)
+                       dst[0] = '\0';
                return NULL;
+       }
 
        dp = dst;
        sp = (const uint8_t *)src;
@@ -68,7 +71,7 @@
 {
        char abuf[256 * 3];
 
-       lla_snprintf(abuf, sizeof(abuf), dl->dl_data, dl->dl_alen);
+       lla_snprintf(abuf, sizeof(abuf), dl->dl_data+dl->dl_nlen, dl->dl_alen);
        return snprintf(buf, len, "%.*s/%hhu#%s",
            (int)dl->dl_nlen, dl->dl_data, dl->dl_type, abuf);
 }



Home | Main Index | Thread Index | Old Index