From 35f093ab7b01bcabbbef8b517945fa0f32950199 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 23 Jun 2023 12:09:07 +0200 Subject: key2root-rmkey, key2root-lskeys: check for NUL byte on truncated line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- key2root-lskeys.c | 4 +++- key2root-rmkey.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/key2root-lskeys.c b/key2root-lskeys.c index 271b0a9..a25b32d 100644 --- a/key2root-lskeys.c +++ b/key2root-lskeys.c @@ -103,8 +103,10 @@ listkeys(int dir, const char *user) } if (rhead != whead) { - fprintf(stderr, "%s: file truncated: %s/%s\n", argv0, KEYPATH, user); failed = 1; + fprintf(stderr, "%s: file truncated: %s/%s\n", argv0, KEYPATH, user); + if (memchr(&data[rhead], '\0', whead - rhead)) + fprintf(stderr, "%s: NUL byte found in %s/%s on line %zu\n", argv0, KEYPATH, user, lineno + 1); } close(fd); diff --git a/key2root-rmkey.c b/key2root-rmkey.c index c55468f..1165435 100644 --- a/key2root-rmkey.c +++ b/key2root-rmkey.c @@ -116,8 +116,11 @@ loadandremove(int fd, char **datap, size_t *lenp, size_t *sizep, const char **ke removekeys(*datap, lenp, &rhead, &rhead2, &lineno, path, keys, nkeysp); } - if (rhead != *lenp) + if (rhead != *lenp) { fprintf(stderr, "%s: file truncated: %s\n", argv0, path); + if (memchr(&(*datap)[rhead], '\0', *lenp - rhead)) + fprintf(stderr, "%s: NUL byte found in %s on line %zu\n", argv0, path, lineno + 1); + } } -- cgit v1.2.3-70-g09d2