[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/6] ios: Check ios->handler_normalize for memory allocation erro
From: |
Tim Rühsen |
Subject: |
[PATCH 3/6] ios: Check ios->handler_normalize for memory allocation error. |
Date: |
Thu, 7 May 2020 12:51:03 +0200 |
2020-05-07 Tim Rühsen <address@hidden>
* bootstrap.conf: Add errno to libpoke_modules.
* libpoke/ios.c (ios_open): Check return value of handler_normalize
for out of memory error.
* libpoke/ios-dev-file.c (ios_dev_file_handler_normalize):
Return NULL with errno=ENOMEM on memory allocation error.
* libpoke/ios-dev-mem.c (ios_dev_mem_handler_normalize): Likewise.
* libpoke/ios-dev-nbd.c (ios_dev_nbd_handler_normalize): Likewise.
---
ChangeLog | 10 ++++++++++
bootstrap.conf | 1 +
libpoke/ios-dev-file.c | 6 ++++--
libpoke/ios-dev-mem.c | 2 +-
libpoke/ios-dev-nbd.c | 2 +-
libpoke/ios.c | 6 +++++-
6 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 6e58d788..7de4afc2 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -64,6 +64,7 @@ libutils_modules="
# gnulib modules used in libpoke/.
libpoke_modules="
+ errno
fstat
gcd
gettext-h
diff --git a/libpoke/ios-dev-file.c b/libpoke/ios-dev-file.c
index baf939a9..8a71411b 100644
--- a/libpoke/ios-dev-file.c
+++ b/libpoke/ios-dev-file.c
@@ -56,9 +56,11 @@ ios_dev_file_handler_normalize (const char *handler)
char *ret;
if (handler[0] == '/' || strspn (handler, safe) == strlen (handler))
- return xstrdup (handler);
+ return strdup (handler);
+
if (asprintf (&ret, "./%s", handler) == -1)
- assert (0);
+ return NULL;
+
return ret;
}
diff --git a/libpoke/ios-dev-mem.c b/libpoke/ios-dev-mem.c
index 936f6c89..88b370ad 100644
--- a/libpoke/ios-dev-mem.c
+++ b/libpoke/ios-dev-mem.c
@@ -40,7 +40,7 @@ static char *
ios_dev_mem_handler_normalize (const char *handler)
{
if (handler[0] == '*' && handler[strlen (handler) - 1] == '*')
- return xstrdup (handler);
+ return strdup (handler);
return NULL;
}
diff --git a/libpoke/ios-dev-nbd.c b/libpoke/ios-dev-nbd.c
index 942cf1be..bb8227b0 100644
--- a/libpoke/ios-dev-nbd.c
+++ b/libpoke/ios-dev-nbd.c
@@ -50,7 +50,7 @@ ios_dev_nbd_handler_normalize (const char *handler)
{
if (startswith (handler, "nbd://")
|| startswith (handler, "nbd+unix://"))
- return xstrdup (handler);
+ return strdup (handler);
return NULL;
}
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)
--
2.26.2
[PATCH 4/6] poke: Add new function pk_assert_alloc, Tim Rühsen, 2020/05/07
[PATCH 5/6] poke: Remove unneeded header includes., Tim Rühsen, 2020/05/07