diff mbox series

[2/2] gpg-interface: avoid buffer overrun in parse_ssh_output()

Message ID a72ebd19-9871-f811-cd5c-72b89dad6c6f@web.de (mailing list archive)
State New, archived
Headers show
Series [1/2] gpg-interface: handle missing " with " gracefully in parse_ssh_output() | expand

Commit Message

René Scharfe Oct. 30, 2021, 5:07 p.m. UTC
If the string "key" we found in the output of ssh-keygen happens to be
located at the very end of the line, then going four characters further
leaves us beyond the end of the string.  Explicitly search for the
space after "key" to handle a missing one gracefully.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
This code was added after v2.33.0.

 gpg-interface.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.33.1

Comments

Junio C Hamano Nov. 1, 2021, 6:07 a.m. UTC | #1
René Scharfe <l.s.r@web.de> writes:

> If the string "key" we found in the output of ssh-keygen happens to be
> located at the very end of the line, then going four characters further
> leaves us beyond the end of the string.  Explicitly search for the
> space after "key" to handle a missing one gracefully.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> This code was added after v2.33.0.

Thanks.

Fabian, we are in -rc phase where we concentrate on fixing bugs in
the new code in 'master'.  A quick ack, "here is a better way to fix
it", or "no, that won't be needed because..." is very much
appreciated.


>  gpg-interface.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gpg-interface.c b/gpg-interface.c
> index 62d340e78a..3838536f0a 100644
> --- a/gpg-interface.c
> +++ b/gpg-interface.c
> @@ -409,9 +409,9 @@ static void parse_ssh_output(struct signature_check *sigc)
>  		goto cleanup;
>  	}
>
> -	key = strstr(line, "key");
> +	key = strstr(line, "key ");
>  	if (key) {
> -		sigc->fingerprint = xstrdup(strstr(line, "key") + 4);
> +		sigc->fingerprint = xstrdup(strstr(line, "key ") + 4);
>  		sigc->key = xstrdup(sigc->fingerprint);
>  	} else {
>  		/*
> --
> 2.33.1
Fabian Stelzer Nov. 1, 2021, 8:33 a.m. UTC | #2
On 30.10.21 19:07, René Scharfe wrote:
> If the string "key" we found in the output of ssh-keygen happens to be
> located at the very end of the line, then going four characters further
> leaves us beyond the end of the string.  Explicitly search for the
> space after "key" to handle a missing one gracefully.
> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> This code was added after v2.33.0.
> 
>  gpg-interface.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gpg-interface.c b/gpg-interface.c
> index 62d340e78a..3838536f0a 100644
> --- a/gpg-interface.c
> +++ b/gpg-interface.c
> @@ -409,9 +409,9 @@ static void parse_ssh_output(struct signature_check *sigc)
>  		goto cleanup;
>  	}
> 
> -	key = strstr(line, "key");
> +	key = strstr(line, "key ");
>  	if (key) {
> -		sigc->fingerprint = xstrdup(strstr(line, "key") + 4);
> +		sigc->fingerprint = xstrdup(strstr(line, "key ") + 4);
>  		sigc->key = xstrdup(sigc->fingerprint);
>  	} else {
>  		/*
> --
> 2.33.1
> 

Thanks. This is obviously correct.
Junio C Hamano Nov. 1, 2021, 5:44 p.m. UTC | #3
Fabian Stelzer <fs@gigacodes.de> writes:

> On 30.10.21 19:07, René Scharfe wrote:
>> If the string "key" we found in the output of ssh-keygen happens to be
>> located at the very end of the line, then going four characters further
>> leaves us beyond the end of the string.  Explicitly search for the
>> space after "key" to handle a missing one gracefully.
>> 
>> Signed-off-by: René Scharfe <l.s.r@web.de>
>> ---
>> This code was added after v2.33.0.
>> 
>> 
>
> Thanks. This is obviously correct.

Thanks, both.  Will apply.
diff mbox series

Patch

diff --git a/gpg-interface.c b/gpg-interface.c
index 62d340e78a..3838536f0a 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -409,9 +409,9 @@  static void parse_ssh_output(struct signature_check *sigc)
 		goto cleanup;
 	}

-	key = strstr(line, "key");
+	key = strstr(line, "key ");
 	if (key) {
-		sigc->fingerprint = xstrdup(strstr(line, "key") + 4);
+		sigc->fingerprint = xstrdup(strstr(line, "key ") + 4);
 		sigc->key = xstrdup(sigc->fingerprint);
 	} else {
 		/*