Module Name: src Committed By: christos Date: Sun Jun 12 17:54:15 UTC 2022
Modified Files: src/external/bsd/blocklist/lib: bl.c Log Message: Handle 0 sized messages (Jose Luis Duran) To generate a diff of this commit: cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/blocklist/lib/bl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/blocklist/lib/bl.c diff -u src/external/bsd/blocklist/lib/bl.c:1.1.1.1 src/external/bsd/blocklist/lib/bl.c:1.2 --- src/external/bsd/blocklist/lib/bl.c:1.1.1.1 Sun Jun 14 21:52:53 2020 +++ src/external/bsd/blocklist/lib/bl.c Sun Jun 12 13:54:15 2022 @@ -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 @@ bl_recv(bl_t b) } ub; int got; ssize_t rlen; + size_t rem; bl_info_t *bi = &b->b_info; got = 0; @@ -503,10 +504,12 @@ bl_recv(bl_t b) 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 @@ bl_recv(bl_t b) 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; }