From 539fc605f9402830860bf2276f6b790bceef6fc6 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Fri, 27 Jun 2008 05:18:17 -1000 Subject: Check return value of asprintf() consistently For instances where the asprintf() was ignored, wrap it in a test to check if it failed. If it failed, log a message and abort. There may be some instances where abort may not be what we want to do, however, we were ignoring the return value completely so if we did get a failure, it would just SIGSEGV. Now it will SIGABRT instead. --- isys/imount.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'isys/imount.c') diff --git a/isys/imount.c b/isys/imount.c index 89a528709..3277a6e6a 100644 --- a/isys/imount.c +++ b/isys/imount.c @@ -43,17 +43,30 @@ int doPwMount(char *dev, char *where, char *fs, char *options) { } if (strstr(fs, "nfs")) { - if (options) - rc = asprintf(&opts, "%s,nolock", options); - else + if (options) { + if (asprintf(&opts, "%s,nolock", options) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } + } else { opts = strdup("nolock"); + } device = strdup(dev); } else { if ((options && strstr(options, "bind") == NULL) && - strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) && *dev != '/') - rc = asprintf(&device, "/dev/%s", dev); - else + strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) && + *dev != '/') { + if (asprintf(&device, "/dev/%s", dev) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } + } else { device = strdup(dev); + } if (options) opts = strdup(options); } -- cgit