poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/6] ios: Check ios->handler_normalize for memory allocation


From: Jose E. Marchesi
Subject: Re: [PATCH 3/6] ios: Check ios->handler_normalize for memory allocation error.
Date: Fri, 08 May 2020 09:25:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

    >     diff --git a/libpoke/ios.c b/libpoke/ios.c
    >     index ebf5f5bc..74fd3719 100644
    >     --- a/libpoke/ios.c
    >     +++ b/libpoke/ios.c
    >     @@ -26,6 +26,7 @@
    >      #include <limits.h>
    >      #define _(str) gettext (str)
    >      #include <streq.h>
    >     +#include <errno.h>
    >     
    >      #include "pk-utils.h"
    >      #include "ios.h"
    >     @@ -120,7 +121,7 @@ ios_open (const char *handler, uint64_t flags, 
int set_cur)
    >      {
    >        struct ios *io = NULL;
    >        struct ios_dev_if **dev_if = NULL;
    >     -  int error, ret;
    >     +  int error = IOD_ERROR, ret;
    >     
    >        /* Allocate and initialize the new IO space.  */
    >        io = xmalloc (sizeof (struct ios));
    >     @@ -130,11 +131,14 @@ ios_open (const char *handler, uint64_t flags, 
int set_cur)
    >     
    >        /* Look for a device interface suitable to operate on the given
    >           handler.  */
    >     +  errno = 0;
    >        for (dev_if = ios_dev_ifs; *dev_if; ++dev_if)
    >          {
    >            io->handler = (*dev_if)->handler_normalize (handler);
    >            if (io->handler)
    >              break;
    >     +      if (errno == ENOMEM)
    >     +        goto error;
    >          }
    >     
    >        if (*dev_if == NULL)
    > 
    > Why would be want to check for `errno' after calling handler_normalize?
    > The function does not return any error code.
    
    handler_normalize may return NULL for two cases: no memory and some
    asprintf error. Or ios_dev_mem_open return NULL if mio is NULL or
    (with NBD) if the URL type is wrong.  That's why I set errno=0 and
    then check for ENOMEM.
    
    ios_dev_file_handler_normalize uses asprintf:
    asprintf man page "If memory  allocation wasn't possible, or some other
    error occurs, these functions will return -1"
    
    ios_dev_nbd_handler_normalize returns NULL if 'handler' has the wrong
    URL type.
    
We better dont' rely on that.  The right thing to do there is to change
the handler_normalize interface so it can report errors.

I think Egeyar is changing the ios_dev interface to make sure every
possible error conditions are reported to the users of the interface...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]