[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch: fix various issues found by static analysis [infokey]
From: |
Gavin Smith |
Subject: |
Re: Patch: fix various issues found by static analysis [infokey] |
Date: |
Tue, 15 Oct 2024 16:41:16 +0100 |
On Tue, Oct 15, 2024 at 12:36:59PM +0200, Vitezslav Crhonek wrote:
> From aae25e4335fa4127b9c3e73486095df304ae735a Mon Sep 17 00:00:00 2001
> From: Vitezslav Crhonek <vcrhonek@redhat.com>
> Date: Tue, 15 Oct 2024 10:58:52 +0200
> Subject: [PATCH 2/7] * info/infokey.c: add initializer
>
> ---
> info/infokey.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/info/infokey.c b/info/infokey.c
> index ec06cec51f..a42f896d3f 100644
> --- a/info/infokey.c
> +++ b/info/infokey.c
> @@ -208,7 +208,7 @@ compile (FILE *fp, const char *filename, int
> *suppress_info, int *suppress_ea)
> int oval = 0;
> char comment[10];
> unsigned int clen = 0;
> - int seq[20];
> + int seq[20] = { 0 };
> unsigned int slen = 0;
> char act[80];
> unsigned int alen = 0;
I'm guessing this does not fix a bug, but the fact that the function is
a "state machine" implemented with a switch statement inside a loop
makes it difficult to immediately confirm that 'seq' is not read before
it is written to, in code such as
/* Only allow "1 menu-digit". (This is useful if
this default binding is disabled with "#stop".)
E.g. do not allow "b menu-digit". */
if (seq[0] != '1' || seq[1] != '\0'
|| section != info)
{
syntax_error (filename, lnum,
_("cannot bind key sequence to menu-digit"));
}
When checking over the code I found a bug that if there were exactly
20 characters in 'seq', then the array would not be null-terminated
for the call to keymap_bind_keyseq, which relies on it being null-terminated.
Hence I fixed this by initialising seq to have an initial 0, and also
always null-terminating the sequence. This may also stop your static
analysis warning.
- Patch: fix various issues found by static analysis, Vitezslav Crhonek, 2024/10/15
- Re: Patch: fix various issues found by static analysis [LONG_MAX], Gavin Smith, 2024/10/15
- Re: Patch: fix various issues found by static analysis [freopen check], Gavin Smith, 2024/10/15
- Re: Patch: fix various issues found by static analysis [infokey],
Gavin Smith <=
- Re: Patch: fix various issues found by static analysis [fclose], Gavin Smith, 2024/10/15
- Re: Patch: fix various issues found by static analysis, Patrice Dumas, 2024/10/15
- Re: Patch: fix various issues found by static analysis, Gavin Smith, 2024/10/15
- Re: Patch: fix various issues found by static analysis, Gavin Smith, 2024/10/16