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

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Jul 26 12:11:16 PDT 2014


On Fri, Jul 25, 2014 at 07:03:20PM +0400, Andrey Borzenkov wrote:
> В 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"?
> 
Applied, with the if fixed.

I also applied some other changes, your patch overwrote some state in enable_sysv_units().

Zbyszek


More information about the systemd-devel mailing list