summaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorHartmut Knaack <knaack.h@gmx.de>2015-05-31 14:40:02 +0200
committerJonathan Cameron <jic23@kernel.org>2015-05-31 19:21:10 +0100
commite9e45b43b8f06273d9b78f187042dff0bf5be0a5 (patch)
tree2e0bb238e6b234a12366c545e879b9b6646b9985 /tools/iio
parent2156b179993e3d5b422976181ba17d91153313e1 (diff)
downloadlinux-e9e45b43b8f06273d9b78f187042dff0bf5be0a5.tar.bz2
tools:iio: catch errors in string allocation
This patch catches errors in string allocation in generic_buffer.c, iio_event_monitor.c, iio_utils.c and lsiio.c. Signed-off-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/generic_buffer.c4
-rw-r--r--tools/iio/iio_event_monitor.c2
-rw-r--r--tools/iio/iio_utils.c9
-rw-r--r--tools/iio/lsiio.c15
4 files changed, 24 insertions, 6 deletions
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index 4cd246426b57..eb89bc2ca5d0 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -234,7 +234,9 @@ int main(int argc, char **argv)
}
printf("iio device number being used is %d\n", dev_num);
- asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
+ ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
+ if (ret < 0)
+ return -ENOMEM;
if (!notrigger) {
if (trigger_name == NULL) {
diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index 578390db1bec..1374374208ee 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -265,6 +265,8 @@ int main(int argc, char **argv)
/* If we can't find a IIO device by name assume device_name is a
IIO chrdev */
chrdev_name = strdup(device_name);
+ if (!chrdev_name)
+ return -ENOMEM;
}
fd = open(chrdev_name, 0);
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 812153ff18c3..f0896f46847f 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -36,7 +36,7 @@ int iioutils_break_up_name(const char *full_name,
char *current;
char *w, *r;
char *working, *prefix = "";
- int i;
+ int i, ret;
for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++)
if (!strncmp(full_name, iio_direction[i],
@@ -46,6 +46,9 @@ int iioutils_break_up_name(const char *full_name,
}
current = strdup(full_name + strlen(prefix) + 1);
+ if (!current)
+ return -ENOMEM;
+
working = strtok(current, "_\0");
w = working;
@@ -59,10 +62,10 @@ int iioutils_break_up_name(const char *full_name,
r++;
}
*w = '\0';
- asprintf(generic_name, "%s_%s", prefix, working);
+ ret = asprintf(generic_name, "%s_%s", prefix, working);
free(current);
- return 0;
+ return (ret == -1) ? -ENOMEM : 0;
}
/**
diff --git a/tools/iio/lsiio.c b/tools/iio/lsiio.c
index 65a2385e2a78..daa6c5312d66 100644
--- a/tools/iio/lsiio.c
+++ b/tools/iio/lsiio.c
@@ -107,7 +107,12 @@ static void dump_devices(void)
if (check_prefix(ent->d_name, type_device)) {
char *dev_dir_name;
- asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
+ if (asprintf(&dev_dir_name, "%s%s", iio_dir,
+ ent->d_name) < 0) {
+ printf("Memory allocation failed\n");
+ goto error_close_dir;
+ }
+
dump_one_device(dev_dir_name);
free(dev_dir_name);
if (verblevel >= VERBLEVEL_SENSORS)
@@ -119,11 +124,17 @@ static void dump_devices(void)
if (check_prefix(ent->d_name, type_trigger)) {
char *dev_dir_name;
- asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
+ if (asprintf(&dev_dir_name, "%s%s", iio_dir,
+ ent->d_name) < 0) {
+ printf("Memory allocation failed\n");
+ goto error_close_dir;
+ }
+
dump_one_trigger(dev_dir_name);
free(dev_dir_name);
}
}
+error_close_dir:
closedir(dp);
}