diff options
author | Ed Maste <emaste@FreeBSD.org> | 2022-07-18 00:43:52 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2022-07-25 14:57:24 +0000 |
commit | 35cdb601016b2dbdb9f5e296ac4b5f42248eddf5 (patch) | |
tree | a4dfc255fc3667635d8e7c0f08ce76642dc68120 /contrib | |
parent | 3be1eaa32b95857cf848295e10ffc25e2852d2e6 (diff) | |
download | src-35cdb601016b2dbdb9f5e296ac4b5f42248eddf5.tar.gz src-35cdb601016b2dbdb9f5e296ac4b5f42248eddf5.zip |
blacklistd: Handle 0 sized messages
Patch obtained from https://github.com/zoulasc/blocklist commit
ada75856bc6fcabbdd25ffbe08fbad5cf2a2c08a
PR: 264599
MFC after: 1 week
(cherry picked from commit b1e81e6ddee42efb0f0d49cfc6cebb48d52e3f08)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/blacklist/lib/bl.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/contrib/blacklist/lib/bl.c b/contrib/blacklist/lib/bl.c index 9f93b91f4c8f..ab2bd7c43ebe 100644 --- a/contrib/blacklist/lib/bl.c +++ b/contrib/blacklist/lib/bl.c @@ -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; @@ -504,10 +505,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); @@ -521,7 +524,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; } |