diff mbox series

[v2,1/3] lib: Check received message was not truncated

Message ID 20180321143927.12156-2-rpalethorpe@suse.com
State Changes Requested
Headers show
Series [v2,1/3] lib: Check received message was not truncated | expand

Commit Message

Richard Palethorpe March 21, 2018, 2:39 p.m. UTC
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 lib/safe_net.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/safe_net.c b/lib/safe_net.c
index 64e2cbcf6..ba38fc08e 100644
--- a/lib/safe_net.c
+++ b/lib/safe_net.c
@@ -240,8 +240,19 @@  ssize_t safe_recvmsg(const char *file, const int lineno, size_t len,
 			 file, lineno, sockfd, msg, flags, rval, len);
 	}
 
-	return rval;
+	if (msg->msg_flags & MSG_TRUNC) {
+		tst_brkm(TBROK, NULL,
+			 "%s:%d: recvmsg(%d, %p, %d): buffer is too small",
+			 file, lineno, sockfd, msg, flags);
+	}
 
+	if (msg->msg_flags & MSG_CTRUNC) {
+		tst_brkm(TBROK, NULL,
+			 "%s:%d: recvmsg(%d, %p, %d): control buffer is too small",
+			 file, lineno, sockfd, msg, flags);
+	}
+
+	return rval;
 }
 
 int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),