From 123a18fe3dad3f115f9e614459b4cd208b47b682 Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 12 Jun 2022 17:54:15 +0000 Subject: [PATCH] Handle 0 sized messages (Jose Luis Duran) --- external/bsd/blocklist/lib/bl.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/external/bsd/blocklist/lib/bl.c b/external/bsd/blocklist/lib/bl.c index 0de82389e888..3eee5d4dbf97 100644 --- a/external/bsd/blocklist/lib/bl.c +++ b/external/bsd/blocklist/lib/bl.c @@ -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 -__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 #include @@ -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; }