Skip to contentSkip to conversation

trace-cmd: Fix a minor bug in `trace-cmd listen`

PATCH In review Slavomir Kaslev 2 participants 2 messages Sep 21, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Fix a minor bug in `trace-cmd listen`

There is a potential bug caused by C's operator precedence when checking the flags set by poll in trace-cmd listen:

			if (!fds[i].revents & POLLIN)
				continue;

vs

			if (!(fds[i].revents & POLLIN))
				continue;

Curiously enough, the bug doesn't manifest itself since POLLIN is equal to 1 and trace-cmd listen waits only for read events so no other flags will be set by poll.

---
 tracecmd/trace-listen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-listen.c +1 -1
index 7bc723e..c05c2d8 100644
@@ -2020,7 +2020,7 @@ static void do_accept_loop(int nfd, int vfd, int mfd)
 				continue;
 			}
 
-			if (!fds[i].revents & POLLIN)
+			if (!(fds[i].revents & POLLIN))
 				continue;
 
 			if (i < FD_CONNECTED) {
Signature · 1 line
2.17.1
#1 lore raw
Quoted 11 lines · On Fri, 21 Sep 2018 15:46:17 +0300 Slavomir Kaslev <[email protected]> wrote:

There is a potential bug caused by C's operator precedence when checking the flags set by poll in trace-cmd listen:

			if (!fds[i].revents & POLLIN)
				continue;

vs

			if (!(fds[i].revents & POLLIN))
				continue;

Nice catch!

Quoted 3 lines

Curiously enough, the bug doesn't manifest itself since POLLIN is equal to 1 and trace-cmd listen waits only for read events so no other flags will be set by poll.

Funny how it worked out that way. Probably why it wasn't caught before, because if it didn't work out that way, it would have shown up quickly and have been fixed!

-- Steve

Quoted 19 lines
---
 tracecmd/trace-listen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-listen.c +1 -1
index 7bc723e..c05c2d8 100644
@@ -2020,7 +2020,7 @@ static void do_accept_loop(int nfd, int vfd, int mfd)
 				continue;
 			}
 
-			if (!fds[i].revents & POLLIN)
+			if (!(fds[i].revents & POLLIN))
 				continue;
 
 			if (i < FD_CONNECTED) {