[PATCH 2/7] request-key: Fix mishandling of last line of config file

From: David Howells
Date: Fri Aug 22 2025 - 10:38:16 EST


Fix mishandling of the config file by /sbin/request-key whereby the last
line of a file, if it is lacking a newline, will trim off the last
character and then try and use that. Return an error instead if we find a
line without a newline char at the end.

Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---
request-key.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/request-key.c b/request-key.c
index bf47c0a..d1feec3 100644
--- a/request-key.c
+++ b/request-key.c
@@ -367,6 +367,8 @@ static void scan_conf_file(struct parameters *params, int dirfd, const char *con
/* ignore blank lines and comments */
if (len == 1 || buf[0] == '#' || isspace(buf[0]))
continue;
+ if (len == 0 || buf[len - 1] != '\n')
+ line_error("Line missing newline\n");

buf[--len] = 0;
p = buf;