Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/net make it always return a NUL terminated string i...



details:   https://anonhg.NetBSD.org/src/rev/ec2c864727e8
branches:  trunk
changeset: 349329:ec2c864727e8
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Dec 07 03:16:45 2016 +0000

description:
make it always return a NUL terminated string instead of NULL when the address
is truncated for compatibility with others.

diffstat:

 lib/libc/net/linkaddr.c |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diffs (49 lines):

diff -r 2e57b502835e -r ec2c864727e8 lib/libc/net/linkaddr.c
--- a/lib/libc/net/linkaddr.c   Wed Dec 07 02:48:54 2016 +0000
+++ b/lib/libc/net/linkaddr.c   Wed Dec 07 03:16:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linkaddr.c,v 1.19 2016/12/07 02:48:54 christos Exp $   */
+/*     $NetBSD: linkaddr.c,v 1.20 2016/12/07 03:16:45 christos Exp $   */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.19 2016/12/07 02:48:54 christos Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.20 2016/12/07 03:16:45 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -148,16 +148,18 @@
 
 #define ADDC(ch) \
        do { \
-               if (out >= obuf + sizeof(obuf)) \
-                       return NULL; \
+               if (out >= obuf + sizeof(obuf) - 1) \
+                       return obuf; \
                *out++ = (ch); \
        } while (/*CONSTCOND*/0)
 
        if (sdl->sdl_nlen) {
                if (sdl->sdl_nlen >= sizeof(obuf))
-                       return NULL;
-               (void)memcpy(obuf, sdl->sdl_data, (size_t)sdl->sdl_nlen);
-               out += sdl->sdl_nlen;
+                       i = sizeof(obuf) - 1;
+               else
+                       i = sdl->sdl_nlen;
+               (void)memcpy(obuf, sdl->sdl_data, i);
+               out += i;
                if (sdl->sdl_alen)
                        ADDC(':');
        }
@@ -176,5 +178,5 @@
                        ADDC(hexlist[i]);
        }
        ADDC('\0');
-       return (obuf);
+       return obuf;
 }



Home | Main Index | Thread Index | Old Index