summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-08-29 13:38:56 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-08-29 15:50:33 +1000
commit91bba3825f53460a187786de8a8cfdf27829087c (patch)
tree27230cd8896b231475f4df79a9276faae5567619
parent1fa866fb7284e018fa2da94a8aa884766dbf09d1 (diff)
device: only strcmp if EVIOCGNAME succeeds
The ioctl may fail under some conditions, causing a erroneous strcmp. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--src/device.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/device.cpp b/src/device.cpp
index 12b3e56..ffe33c6 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -77,8 +77,8 @@ void xorg::testing::evemu::Device::GuessDeviceNode(time_t ctime) {
int fd = open(s.str().c_str(), O_RDONLY);
char device_name[256];
- ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name);
- if (strcmp(device_name, evemu_get_name(d_->device)) == 0) {
+ if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) != -1 &&
+ strcmp(device_name, evemu_get_name(d_->device)) == 0) {
struct stat buf;
if (fstat(fd, &buf) == 0) {
if (buf.st_ctime >= ctime) {