diff options
author | David Cantrell <dcantrell@redhat.com> | 2008-06-26 09:32:32 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2008-06-26 09:32:57 -1000 |
commit | 70b45f0621c98444dd5f1ce3eb5a77033d31c97d (patch) | |
tree | 80028ebb6b10d22715057ef47a8a7dfaefbbcd3a /isys | |
parent | 46161892b35ff5e87c0eabae2aa39e31bf9de4c0 (diff) | |
download | anaconda-70b45f0621c98444dd5f1ce3eb5a77033d31c97d.tar.gz anaconda-70b45f0621c98444dd5f1ce3eb5a77033d31c97d.tar.xz anaconda-70b45f0621c98444dd5f1ce3eb5a77033d31c97d.zip |
Use strtol() instead of atoi()
Code cleanup patch. Use strtol() to convert strings to
ints, rather than atoi(). No error checking capability
with atoi(). Also add error handling to detect strtol
failures.
Diffstat (limited to 'isys')
-rw-r--r-- | isys/devices.c | 28 | ||||
-rw-r--r-- | isys/isys.c | 8 | ||||
-rw-r--r-- | isys/silo.c | 20 |
3 files changed, 51 insertions, 5 deletions
diff --git a/isys/devices.c b/isys/devices.c index 69a002053..06dcd8ec7 100644 --- a/isys/devices.c +++ b/isys/devices.c @@ -29,6 +29,7 @@ #include <stdlib.h> #include <unistd.h> #include <sys/types.h> +#include <limits.h> #include "devices.h" @@ -72,8 +73,15 @@ struct device **getDevices(enum deviceType type) { close(fd); continue; } + close(fd); caps = strtol(buf, NULL, 16); + + if ((errno == ERANGE && (caps == LONG_MIN || caps == LONG_MAX)) || + (errno != 0 && caps == 0)) { + return NULL; + } + if (caps & GENHD_FL_CD) devtype = DEVICE_CDROM; else @@ -86,14 +94,23 @@ struct device **getDevices(enum deviceType type) { snprintf(path, 64, "/sys/block/%s/size", ent->d_name); fd = open(path, O_RDONLY); + if (fd == -1) continue; if (read(fd, buf, 64) <= 0) { close(fd); continue; } + close(fd); - size = atoi(buf); + size = strtol(buf, NULL, 10); + + if ((errno == ERANGE && (size == LONG_MIN || + size == LONG_MAX)) || + (errno != 0 && size == 0)) { + return NULL; + } + if (size < MINIMUM_INTERESTING_SIZE) continue; } @@ -135,8 +152,15 @@ storagedone: close(fd); continue; } + close(fd); - type = atoi(buf); + type = strtol(buf, NULL, 10); + + if ((errno == ERANGE && (type == LONG_MIN || type == LONG_MAX)) || + (errno != 0 && type == 0)) { + return NULL; + } + if (type != 1) continue; diff --git a/isys/isys.c b/isys/isys.c index d1798d566..e2b40cb87 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -548,7 +548,13 @@ static PyObject * doConfigNetDevice(PyObject * s, PyObject * args) { cfg.ipv6 = ip_addr_in6(&addr6); if (strlen(prefix)) - i = atoi(prefix); + i = strtol(prefix, NULL, 10); + + if ((errno == ERANGE && (i == LONG_MIN || i == LONG_MAX)) || + (errno != 0 && i == 0)) { + return NULL; + } + if (i > 0 && i <= 128) cfg.ipv6_prefixlen = i; } diff --git a/isys/silo.c b/isys/silo.c index 66109c6c4..c0eabdbc5 100644 --- a/isys/silo.c +++ b/isys/silo.c @@ -480,7 +480,15 @@ scan_scsi(void) { while ((enthba = readdir(dirhba))) { if (enthba->d_name[0] == '.') continue; - host = atoi(enthba->d_name); + host = strtol(enthba->d_name, NULL, 10); + + if ((errno == ERANGE && (host == LONG_MIN || host == LONG_MAX)) || + (errno != 0 && host == 0)) { + logMessage(ERROR, "%s: %d: %s", __func__, __LINE__, + strerror(errno)); + abort(); + } + sprintf (path, "/proc/scsi/%s/%s", ent->d_name, enthba->d_name); f = fopen (path, "r"); if (f == NULL) continue; @@ -799,7 +807,15 @@ disk2PromPath (PyObject *self, PyObject *args) else if (!disk[0]) part = 3; else { - part = atoi (disk); + part = strtol (disk, NULL, 10); + + if ((errno == ERANGE && (part == LONG_MIN || part == LONG_MAX)) || + (errno != 0 && part == 0)) { + logMessage(ERROR, "%s: %d: %s", __func__, __LINE__, + strerror(errno)); + abort(); + } + if (part <= 0 || part > 8) part = -1; } if (diskno < 0 || part == -1 || |