[systemd-devel] [PATCH] always check asprintf return code

Andrey Borzenkov arvidjaar at gmail.com
Fri Jul 25 08:03:20 PDT 2014


В Fri, 25 Jul 2014 15:38:31 +0200
Karel Zak <kzak at redhat.com> пишет:

> There is a small number of the places in sources where we don't check
> asprintf() return code and assume that after error the function
> returns NULL pointer via the first argument. That's wrong, after
> error the content of pointer is undefined.
> ---
>  src/core/unit-printf.c                              |  8 +++++---
>  src/cryptsetup/cryptsetup.c                         | 11 ++++++++---
>  src/journal/coredump.c                              |  5 ++---
>  src/journal/journalctl.c                            | 16 +++++++++++-----
>  src/run/run.c                                       | 16 ++++++++--------
>  src/shared/install.c                                | 15 +++++++++------
>  src/systemctl/systemctl.c                           | 14 ++++++++------
>  src/tty-ask-password-agent/tty-ask-password-agent.c |  5 +++--
>  8 files changed, 54 insertions(+), 36 deletions(-)
> 
> diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
> index 5bd30f0..8ac2081 100644
> --- a/src/core/unit-printf.c
> +++ b/src/core/unit-printf.c
> @@ -208,7 +208,9 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
> @@ -230,8 +232,8 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
>  
>                  if (specifier == 'u')
>                          printed = strdup(username);
> -                else
> -                        asprintf(&printed, UID_FMT, uid);
> +                else (asprintf(&printed, UID_FMT, uid) < 0)

Missing "if"?

> +                        return -ENOMEM;
>          }
>  
>          if (!printed)


More information about the systemd-devel mailing list