From 99065f078115b86979add9f4575dde09e16e3cb5 Mon Sep 17 00:00:00 2001 From: zhaozihanzzh Date: Wed, 10 Apr 2024 21:41:05 +0800 Subject: [PATCH 1/2] Fix cplen calculation --- adapter/syscall/ff_hook_syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/syscall/ff_hook_syscall.c b/adapter/syscall/ff_hook_syscall.c index 03ca09a57..4d9dd44e4 100644 --- a/adapter/syscall/ff_hook_syscall.c +++ b/adapter/syscall/ff_hook_syscall.c @@ -419,7 +419,7 @@ ff_hook_getsockname(int fd, struct sockaddr *name, SYSCALL(FF_SO_GETSOCKNAME, args); if (ret == 0) { - socklen_t cplen = *namelen ? *sh_namelen > *namelen + socklen_t cplen = *namelen < *sh_namelen ? *namelen : *sh_namelen; rte_memcpy(name, sh_name, cplen); *namelen = *sh_namelen; From d0c4ca97ead79ad6e555dda0289e15183109df72 Mon Sep 17 00:00:00 2001 From: zhaozihanzzh Date: Thu, 18 Apr 2024 22:58:58 +0800 Subject: [PATCH 2/2] Fix cplen calculation errors in ff_hook_syscall.c This commit also modifies the style of the previous fix to be in tune with the original ff_hook_accept. --- adapter/syscall/ff_hook_syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adapter/syscall/ff_hook_syscall.c b/adapter/syscall/ff_hook_syscall.c index 4d9dd44e4..3681d1529 100644 --- a/adapter/syscall/ff_hook_syscall.c +++ b/adapter/syscall/ff_hook_syscall.c @@ -419,7 +419,7 @@ ff_hook_getsockname(int fd, struct sockaddr *name, SYSCALL(FF_SO_GETSOCKNAME, args); if (ret == 0) { - socklen_t cplen = *namelen < *sh_namelen ? *namelen + socklen_t cplen = *sh_namelen > *namelen ? *namelen : *sh_namelen; rte_memcpy(name, sh_name, cplen); *namelen = *sh_namelen; @@ -475,7 +475,7 @@ ff_hook_getpeername(int fd, struct sockaddr *name, SYSCALL(FF_SO_GETPEERNAME, args); if (ret == 0) { - socklen_t cplen = *namelen ? *sh_namelen > *namelen + socklen_t cplen = *sh_namelen > *namelen ? *namelen : *sh_namelen; rte_memcpy(name, sh_name, cplen); *namelen = *sh_namelen; @@ -794,7 +794,7 @@ ff_hook_recvfrom(int fd, void *buf, size_t len, int flags, if (ret >= 0) { rte_memcpy(buf, sh_buf, ret); if (from) { - socklen_t cplen = *fromlen ? *sh_fromlen > *fromlen + socklen_t cplen = *sh_fromlen > *fromlen ? *fromlen : *sh_fromlen; rte_memcpy(from, sh_from, cplen); *fromlen = *sh_fromlen;