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

David Howells posted 7 patches 1 month, 1 week ago
[PATCH 2/7] request-key: Fix mishandling of last line of config file
Posted by David Howells 1 month, 1 week ago
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@redhat.com>
---
 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;
Re: [PATCH 2/7] request-key: Fix mishandling of last line of config file
Posted by Jarkko Sakkinen 1 month, 1 week ago
On Fri, Aug 22, 2025 at 03:22:09PM +0100, David Howells wrote:
> 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@redhat.com>
> ---
>  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;
> 

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

Looks good to me. And the next question is not directly related to
this patch per se.

Just a hypothetical question. What if for spurious reasons the config
file would have carriage returns?

BR, Jarkko