From a6856129ec0b72c15788bdb56f6b1584cbea07bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 22 Nov 2017 10:32:45 +0100 Subject: [PATCH] udev: "handle" oom in path_id path_prepend returned a status code, but it wasn't looked at anywhere. Adding checks for the return value in all the bazillion places where it is called is not very attractive, so let's just make the whole program abort cleanly if the (very unlikely) oom is encountered. --- src/udev/udev-builtin-path_id.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 6e3bf4f5bbd..9ce2079a67e 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -34,11 +34,12 @@ #include "dirent-util.h" #include "fd-util.h" #include "string-util.h" +#include "sysexits.h" #include "udev.h" #include "udev-util.h" _printf_(2,3) -static int path_prepend(char **path, const char *fmt, ...) { +static void path_prepend(char **path, const char *fmt, ...) { va_list va; _cleanup_free_ char *pre = NULL; int r; @@ -46,36 +47,40 @@ static int path_prepend(char **path, const char *fmt, ...) { va_start(va, fmt); r = vasprintf(&pre, fmt, va); va_end(va); - if (r < 0) - return -ENOMEM; + if (r < 0) { + log_oom(); + exit(EX_OSERR); + } if (*path) { char *new; new = strjoin(pre, "-", *path); - if (!new) - return -ENOMEM; + if (!new) { + log_oom(); + exit(EX_OSERR); + } + free_and_replace(*path, new); } else { *path = pre; pre = NULL; } - - return 0; } /* ** Linux only supports 32 bit luns. ** See drivers/scsi/scsi_scan.c::scsilun_to_int() for more details. */ -static int format_lun_number(struct udev_device *dev, char **path) { +static void format_lun_number(struct udev_device *dev, char **path) { unsigned long lun = strtoul(udev_device_get_sysnum(dev), NULL, 10); - /* address method 0, peripheral device addressing with bus id of zero */ if (lun < 256) - return path_prepend(path, "lun-%lu", lun); - /* handle all other lun addressing methods by using a variant of the original lun format */ - return path_prepend(path, "lun-0x%04lx%04lx00000000", lun & 0xffff, (lun >> 16) & 0xffff); + /* address method 0, peripheral device addressing with bus id of zero */ + path_prepend(path, "lun-%lu", lun); + else + /* handle all other lun addressing methods by using a variant of the original lun format */ + path_prepend(path, "lun-0x%04lx%04lx00000000", lun & 0xffff, (lun >> 16) & 0xffff); } static struct udev_device *skip_subsystem(struct udev_device *dev, const char *subsys) { -- 2.47.3