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.
This commit is contained in:
zhaozihanzzh 2024-04-18 22:58:58 +08:00
parent 99065f0781
commit d0c4ca97ea
1 changed files with 3 additions and 3 deletions

View File

@ -419,7 +419,7 @@ ff_hook_getsockname(int fd, struct sockaddr *name,
SYSCALL(FF_SO_GETSOCKNAME, args); SYSCALL(FF_SO_GETSOCKNAME, args);
if (ret == 0) { if (ret == 0) {
socklen_t cplen = *namelen < *sh_namelen ? *namelen socklen_t cplen = *sh_namelen > *namelen ? *namelen
: *sh_namelen; : *sh_namelen;
rte_memcpy(name, sh_name, cplen); rte_memcpy(name, sh_name, cplen);
*namelen = *sh_namelen; *namelen = *sh_namelen;
@ -475,7 +475,7 @@ ff_hook_getpeername(int fd, struct sockaddr *name,
SYSCALL(FF_SO_GETPEERNAME, args); SYSCALL(FF_SO_GETPEERNAME, args);
if (ret == 0) { if (ret == 0) {
socklen_t cplen = *namelen ? *sh_namelen > *namelen socklen_t cplen = *sh_namelen > *namelen ? *namelen
: *sh_namelen; : *sh_namelen;
rte_memcpy(name, sh_name, cplen); rte_memcpy(name, sh_name, cplen);
*namelen = *sh_namelen; *namelen = *sh_namelen;
@ -794,7 +794,7 @@ ff_hook_recvfrom(int fd, void *buf, size_t len, int flags,
if (ret >= 0) { if (ret >= 0) {
rte_memcpy(buf, sh_buf, ret); rte_memcpy(buf, sh_buf, ret);
if (from) { if (from) {
socklen_t cplen = *fromlen ? *sh_fromlen > *fromlen socklen_t cplen = *sh_fromlen > *fromlen ? *fromlen
: *sh_fromlen; : *sh_fromlen;
rte_memcpy(from, sh_from, cplen); rte_memcpy(from, sh_from, cplen);
*fromlen = *sh_fromlen; *fromlen = *sh_fromlen;