[PATCH xorg-gtest 2/6] device: only strcmp if EVIOCGNAME succeeds

Peter Hutterer peter.hutterer at who-t.net
Tue Aug 28 23:14:30 PDT 2012


The ioctl may fail under some conditions, causing a erroneous strcmp.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/device.cpp | 4 ++--
 1 file 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) {
-- 
1.7.11.2



More information about the xorg-devel mailing list