diff mbox series

[31/38] trace-cmd listen: prevent a infinite loop in communicate_with_client()

Message ID 20240605134054.2626953-32-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit e3457910846566806faa82df2a15227187886156
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
The loop used to read the option is obviously wrong. If the option
isn't read with one call to read(), it will loop indefinitely. Move
the setting of the initial values out of the loop.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 tracecmd/trace-listen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index da46d09e..af9e3454 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -452,9 +452,9 @@  static int communicate_with_client(struct tracecmd_msg_handle *msg_handle)
 				goto out;
 
 			ret = -EIO;
+			t = size;
+			s = 0;
 			do {
-				t = size;
-				s = 0;
 				s = read(fd, option+s, t);
 				if (s <= 0) {
 					free(option);