aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-06-23 12:09:07 +0200
committerMattias Andrée <maandree@kth.se>2023-06-23 12:09:07 +0200
commit35f093ab7b01bcabbbef8b517945fa0f32950199 (patch)
treefefdb02e6588b79a2540589e00d4739e1f4f91a7
parentkey2root-addkey: mkdir /etc/key2root before saving changes (diff)
downloadkey2root-35f093ab7b01bcabbbef8b517945fa0f32950199.tar.gz
key2root-35f093ab7b01bcabbbef8b517945fa0f32950199.tar.bz2
key2root-35f093ab7b01bcabbbef8b517945fa0f32950199.tar.xz
key2root-rmkey, key2root-lskeys: check for NUL byte on truncated line
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--key2root-lskeys.c4
-rw-r--r--key2root-rmkey.c5
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);
+ }
}