1195972f6Sopenharmony_ciFrom 92091a697ae8dac4026fd75a421ad9464aaa253e Mon Sep 17 00:00:00 2001
2195972f6Sopenharmony_ciFrom: jiangheng <jiangheng14@huawei.com>
3195972f6Sopenharmony_ciDate: Wed, 25 Oct 2023 15:44:19 +0800
4195972f6Sopenharmony_ciSubject: [PATCH 76/77] fix recvmsg return EINVAL
5195972f6Sopenharmony_ci
6195972f6Sopenharmony_ci---
7195972f6Sopenharmony_ci src/api/sockets.c | 12 ++++++++++++
8195972f6Sopenharmony_ci 1 file changed, 12 insertions(+)
9195972f6Sopenharmony_ci
10195972f6Sopenharmony_cidiff --git a/src/api/sockets.c b/src/api/sockets.c
11195972f6Sopenharmony_ciindex b6c7b05..1d71427 100644
12195972f6Sopenharmony_ci--- a/src/api/sockets.c
13195972f6Sopenharmony_ci+++ b/src/api/sockets.c
14195972f6Sopenharmony_ci@@ -1492,9 +1492,21 @@ lwip_recvmsg(int s, struct msghdr *message, int flags)
15195972f6Sopenharmony_ci   /* check for valid vectors */
16195972f6Sopenharmony_ci   buflen = 0;
17195972f6Sopenharmony_ci   for (i = 0; i < message->msg_iovlen; i++) {
18195972f6Sopenharmony_ci+#if GAZELLE_ENABLE
19195972f6Sopenharmony_ci+    /* msg_iov[i].iov_len == 0 dont return ERRVAL
20195972f6Sopenharmony_ci+     * According to the Single Unix Specification we should return EINVAL if an elment length is < 0
21195972f6Sopenharmony_ci+     * when cast to ssize_t
22195972f6Sopenharmony_ci+     */
23195972f6Sopenharmony_ci+    if ((message->msg_iov[i].iov_base == NULL) || ((ssize_t)message->msg_iov[i].iov_len < 0) ||
24195972f6Sopenharmony_ci+#else
25195972f6Sopenharmony_ci     if ((message->msg_iov[i].iov_base == NULL) || ((ssize_t)message->msg_iov[i].iov_len <= 0) ||
26195972f6Sopenharmony_ci+#endif
27195972f6Sopenharmony_ci         ((size_t)(ssize_t)message->msg_iov[i].iov_len != message->msg_iov[i].iov_len) ||
28195972f6Sopenharmony_ci+#if GAZELLE_ENABLE
29195972f6Sopenharmony_ci+        ((ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len) < 0)) {
30195972f6Sopenharmony_ci+#else
31195972f6Sopenharmony_ci         ((ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len) <= 0)) {
32195972f6Sopenharmony_ci+#endif
33195972f6Sopenharmony_ci       sock_set_errno(sock, err_to_errno(ERR_VAL));
34195972f6Sopenharmony_ci       done_socket(sock);
35195972f6Sopenharmony_ci       return -1;
36195972f6Sopenharmony_ci-- 
37195972f6Sopenharmony_ci2.27.0
38195972f6Sopenharmony_ci
39