[LTP] [PATCH v2 1/3] lib: Check received message was not truncated
Richard Palethorpe
rpalethorpe@suse.com
Wed Mar 21 15:39:25 CET 2018
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
lib/safe_net.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
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),
--
2.16.2
More information about the ltp
mailing list