Skip to contentSkip to conversation

Possible infinite loop in inotify code

Bluez-devel Bastien Nocera 2 participants 3 messages Oct 4, 2007 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Heya,

Uli mentioned a possible infinite loop in some circumstances:
https://bugzilla.redhat.com/show_bug.cgi?id=235307

Although I wasn't able to reproduce the bug, the attached patch looks technically correct.

Cheers

Signature · 1 line
Bastien Nocera <[email protected]> 

? .deps
? .libs
? Makefile
? Makefile.in
? bluez-utils-better-inotify-error.patch
? test_textfile
Index: notify-inotify.c
===================================================================
RCS file: /cvsroot/bluez/utils/common/notify-inotify.c,v retrieving revision 1.8

notify-inotify.c +9 -2
diff -u -p -r1.8 notify-inotify.c
@@ -60,14 +60,21 @@ static gboolean io_event(GIOChannel *cha
 	memset(buf, 0, sizeof(buf));
 
 	err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf) - 1, &len);
-	if (err == G_IO_ERROR_AGAIN)
+	if (err == G_IO_STATUS_AGAIN) {
 		return TRUE;
+	} else if (err != G_IO_STATUS_NORMAL) {
+		error("Error reading from channel: No error given");
+		return FALSE;
+	}
 
 	while (len >= sizeof(struct inotify_event)) {
 		struct inotify_event *evt = (struct inotify_event *) ptr;
 
-		if (evt->wd != wd || !callback)
+		if (evt->wd != wd || !callback) {
+			len -= sizeof(struct inotify_event) + evt->len;
+			ptr += sizeof(struct inotify_event) + evt->len;
 			continue;
+		}
 
 		if (evt->mask & (IN_CREATE | IN_MOVED_TO))
 			callback(NOTIFY_CREATE, evt->name, NULL);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#1 lore raw

Hi Bastien,

Quoted 5 lines

Uli mentioned a possible infinite loop in some circumstances:
https://bugzilla.redhat.com/show_bug.cgi?id=235307

Although I wasn't able to reproduce the bug, the attached patch looks technically correct.

I reworked the patch a little bit and applied it. The G_IO_STATUS_AGAIN and G_IO_ERROR_AGAIN are not guaranteed to be the same.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw
Quoted 10 lines · Marcel Holtmann

Hi Bastien,

Quoted 5 lines

Uli mentioned a possible infinite loop in some circumstances:
https://bugzilla.redhat.com/show_bug.cgi?id=235307

Although I wasn't able to reproduce the bug, the attached patch looks technically correct.

I reworked the patch a little bit and applied it. The G_IO_STATUS_AGAIN and G_IO_ERROR_AGAIN are not guaranteed to be the same.

My mistake, I made the first patch using g_io_channel_read_chars instead of the deprecated g_io_channel_read and changed the code accordingly (including possible retvals), but then remembered eglib. I guess I didn't completely revert those changes.

Cheers

Signature · 12 lines
Bastien Nocera <[email protected]> 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel