Handle 0 sized messages (Jose Luis Duran)

This commit is contained in:
christos 2022-06-12 17:54:15 +00:00
parent 37beea0d2d
commit 123a18fe3d
1 changed files with 11 additions and 5 deletions

View File

@ -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;
}