fix segfault in recvmsg when msg argument is NULL

Submitted by zhuyan (M) on Jan. 26, 2021, 2:32 a.m.

Details

Message ID 19ad44ec8af24e8e8b70860f46438b19@huawei.com
State New
Headers show

Patch hide | download patch | download mbox

diff --git a/src/network/recvmsg.c b/src/network/recvmsg.c index 03641625..c36ffb8d 100644
--- a/src/network/recvmsg.c
+++ b/src/network/recvmsg.c
@@ -4,6 +4,7 @@ 
 #include <sys/time.h>
 #include <string.h>
 #include "syscall.h"
+#include <errno.h>
 
 hidden void __convert_scm_timestamps(struct msghdr *, socklen_t);
 
@@ -49,6 +50,8 @@  void __convert_scm_timestamps(struct msghdr *msg, socklen_t csize)
 
 ssize_t recvmsg(int fd, struct msghdr *msg, int flags)  {
+	if (!msg) return -EINVAL;
+
 	ssize_t r;
 	socklen_t orig_controllen = msg->msg_controllen;  #if LONG_MAX > INT_MAX
--
2.12.3