Hi Anton,

On Wed, 2024-10-23 at 13:09 +0300, ant.v.morya...@gmail.com wrote:
> From: AntonMoryakov <ant.v.morya...@gmail.com>
> 
> fix: fixed null pointer inference error in process_file function
> 
> Fixed a bug that could cause the program to crash when processing files 
> without a suffix.

Do you have a testcase for this?

> Added a NULL check for the suffix pointer before calling stpcpy().

See comments below about where to put this check and the formatting.

Please also see the CONTRIBUTING file for how to submit patches for
inclusion. In particular the section "Sign your work"
https://sourceware.org/cgit/elfutils/tree/CONTRIBUTING

> ---
>  src/elflint.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/elflint.c b/src/elflint.c
> index cdc6108d..14346045 100644
> --- a/src/elflint.c
> +++ b/src/elflint.c
> @@ -257,7 +257,12 @@ process_file (int fd, Elf *elf, const char *prefix, 
> const char *suffix,
>         {
>           cp = mempcpy (cp, prefix, prefix_len);
>           *cp++ = '(';
> -         strcpy (stpcpy (new_suffix, suffix), ")");
> +             if(suffix != NULL){

Could this check go with the if statement just before this code?

>         /* Create the full name of the file.  */
>         if (prefix != NULL)

So that it reads if (prefix != NULL && suffix != NULL)

> +             strcpy (stpcpy (new_suffix, suffix), ")");
> +             }
> +             else{
> +                     new_suffix[0] = '\0';
> +             }
>         }
>       else
>         new_suffix[0] = '\0';

Note that the code formatting/indenting seems a little off.
In general the elfutils code follows the GNU coding standard
Formatting:
https://www.gnu.org/prep/standards/standards.html#Formatting

Thanks,

Mark

Reply via email to