Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/blocklist/lib Handle 0 sized messages (Jose Lui...



details:   https://anonhg.NetBSD.org/src/rev/0730ef3906b1
branches:  trunk
changeset: 366762:0730ef3906b1
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jun 12 17:54:15 2022 +0000

description:
Handle 0 sized messages (Jose Luis Duran)

diffstat:

 external/bsd/blocklist/lib/bl.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (53 lines):

diff -r b9d04fdb71df -r 0730ef3906b1 external/bsd/blocklist/lib/bl.c
--- a/external/bsd/blocklist/lib/bl.c   Sun Jun 12 16:22:37 2022 +0000
+++ b/external/bsd/blocklist/lib/bl.c   Sun Jun 12 17:54:15 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bl.c,v 1.1.1.1 2020/06/15 01:52:53 christos Exp $      */
+/*     $NetBSD: bl.c,v 1.2 2022/06/12 17:54:15 christos Exp $  */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: bl.c,v 1.1.1.1 2020/06/15 01:52:53 christos Exp $");
+__RCSID("$NetBSD: bl.c,v 1.2 2022/06/12 17:54:15 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -434,6 +434,7 @@
        } ub;
        int got;
        ssize_t rlen;
+       size_t rem;
        bl_info_t *bi = &b->b_info;
 
        got = 0;
@@ -503,10 +504,12 @@
                return NULL;
        }
 
-       if ((size_t)rlen <= sizeof(ub.bl)) {
+       rem = (size_t)rlen;
+       if (rem < sizeof(ub.bl)) {
                bl_log(b->b_fun, LOG_ERR, "message too short %zd", rlen);
                return NULL;
        }
+       rem -= sizeof(ub.bl);
 
        if (ub.bl.bl_version != BL_VERSION) {
                bl_log(b->b_fun, LOG_ERR, "bad version %d", ub.bl.bl_version);
@@ -520,7 +523,10 @@
        bi->bi_uid = -1;
        bi->bi_gid = -1;
 #endif
-       strlcpy(bi->bi_msg, ub.bl.bl_data, MIN(sizeof(bi->bi_msg),
-           ((size_t)rlen - sizeof(ub.bl) + 1)));
+       rem = MIN(sizeof(bi->bi_msg), rem);
+       if (rem == 0)
+               bi->bi_msg[0] = '\0';
+       else
+               strlcpy(bi->bi_msg, ub.bl.bl_data, rem);
        return bi;
 }



Home | Main Index | Thread Index | Old Index