diff mbox series

[BlueZ,3/9] l2test: Add missing error checking

Message ID 20240530150057.444585-4-hadess@hadess.net
State New
Headers show
Series Fix a number of static analysis issues #3 | expand

Commit Message

Bastien Nocera May 30, 2024, 2:57 p.m. UTC
send() might fail and return a negative len, catch that to avoid
advancing the send buffer in the wrong direction and causing all sorts
of problems.

977|->			len = send(sk, buf + sent, buflen, 0);
978|
979|			sent += len;
---
 tools/l2test.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/tools/l2test.c b/tools/l2test.c
index 011a68c3781e..7b6c36e165da 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -975,6 +975,11 @@  static void do_send(int sk)
 			buflen = (size > omtu) ? omtu : size;
 
 			len = send(sk, buf + sent, buflen, 0);
+			if (len < 0) {
+				syslog(LOG_ERR, "Send failed: %s (%d)",
+							strerror(errno), errno);
+				exit(1);
+			}
 
 			sent += len;
 			size -= len;