diff options
author | David Cantrell <dcantrell@redhat.com> | 2008-06-27 05:18:17 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2008-06-27 05:18:17 -1000 |
commit | 539fc605f9402830860bf2276f6b790bceef6fc6 (patch) | |
tree | 49863a7fde8eab8b7bbc8309cb957190284be002 /isys | |
parent | 83389b2effe828debfbbcbebf87dbfd2cc12e361 (diff) | |
download | anaconda-539fc605f9402830860bf2276f6b790bceef6fc6.tar.gz anaconda-539fc605f9402830860bf2276f6b790bceef6fc6.tar.xz anaconda-539fc605f9402830860bf2276f6b790bceef6fc6.zip |
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.
Diffstat (limited to 'isys')
-rw-r--r-- | isys/devices.c | 34 | ||||
-rw-r--r-- | isys/imount.c | 25 | ||||
-rw-r--r-- | isys/isys.c | 14 |
3 files changed, 54 insertions, 19 deletions
diff --git a/isys/devices.c b/isys/devices.c index 2e3760ecc..e312a43e9 100644 --- a/isys/devices.c +++ b/isys/devices.c @@ -50,7 +50,6 @@ struct device **getDevices(enum deviceType type) { struct device **ret = NULL; struct device *new; int numdevices = 0; - int rc; if (type & (DEVICE_DISK | DEVICE_CDROM)) { DIR *dir; @@ -120,7 +119,13 @@ struct device **getDevices(enum deviceType type) { new = calloc(1, sizeof(struct device)); new->device = strdup(ent->d_name); /* FIXME */ - rc = asprintf(&new->description,"Storage device %s",new->device); + if (asprintf(&new->description, "Storage device %s", + new->device) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } new->type = devtype; if (caps & GENHD_FL_REMOVABLE) { new->priv.removable = 1; @@ -175,16 +180,29 @@ storagedone: if (fd != -1) { if (read(fd, buf, 64) > 0) { int i; - for (i = (strlen(buf)-1); isspace(buf[i]); i--) buf[i] = '\0'; + for (i = (strlen(buf)-1); isspace(buf[i]); i--) + buf[i] = '\0'; new->priv.hwaddr = strdup(buf); } } - if (new->priv.hwaddr) - rc = asprintf(&new->description, "Ethernet device %s - %s", - new->device, new->priv.hwaddr); - else - rc = asprintf(&new->description, "Ethernet device %s", new->device); + if (new->priv.hwaddr) { + if (asprintf(&new->description, "Ethernet device %s - %s", + new->device, new->priv.hwaddr) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } + } else { + if (asprintf(&new->description, "Ethernet device %s", + new->device) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } + } ret = realloc(ret, (numdevices+2) * sizeof(struct device)); ret[numdevices] = new; 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); } diff --git a/isys/isys.c b/isys/isys.c index 31786df1e..f33872c99 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -601,12 +601,16 @@ static PyObject * doDhcpNetDevice(PyObject * s, PyObject * args) { /* if we lack a user-provided dhcpclass, construct the default */ if ((dhcpclass == NULL) || (strlen(dhcpclass) == 0)) { - if (uname(&kv) == -1) + if (uname(&kv) == -1) { dhcpclass = "anaconda"; - else { - int ret; - ret = asprintf(&dhcpclass, "anaconda-%s %s %s", - kv.sysname, kv.release, kv.machine); + } else { + if (asprintf(&dhcpclass, "anaconda-%s %s %s", + kv.sysname, kv.release, kv.machine) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } } } |