diff mbox series

svc_fd_create: skip getsockname on a non-network socket

Message ID 20241014085525.2067-1-chenhx.fnst@fujitsu.com (mailing list archive)
State New
Headers show
Series svc_fd_create: skip getsockname on a non-network socket | expand

Commit Message

Chen Hanxiao Oct. 14, 2024, 8:55 a.m. UTC
As svcfd_create(3) said, it can:
Create a service on top of any open file descriptor.

But getsockname and getpeername in svc_fd_create assume that
fd should be a connected socket.

This patch will leave xp_raddr and xp_laddr uninitialized
if fd is not a connected socket.

Signed-off-by: Chen Hanxiao <chenhx.fnst@fujitsu.com>
---
 src/svc_vc.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Steve Dickson Oct. 16, 2024, 2:53 p.m. UTC | #1
On 10/14/24 4:55 AM, Chen Hanxiao wrote:
> As svcfd_create(3) said, it can:
> Create a service on top of any open file descriptor.
> 
> But getsockname and getpeername in svc_fd_create assume that
> fd should be a connected socket.
> 
> This patch will leave xp_raddr and xp_laddr uninitialized
> if fd is not a connected socket.
> 
> Signed-off-by: Chen Hanxiao <chenhx.fnst@fujitsu.com>
Committed... (tag: libtirpc-1-3-6-rc3)

steved.
> ---
>   src/svc_vc.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/src/svc_vc.c b/src/svc_vc.c
> index 3dc8a75..438cbc5 100644
> --- a/src/svc_vc.c
> +++ b/src/svc_vc.c
> @@ -59,6 +59,7 @@
>   #include <rpc/rpc.h>
>   
>   #include "rpc_com.h"
> +#include "debug.h"
>   
>   #include <getpeereid.h>
>   
> @@ -232,6 +233,12 @@ svc_fd_create(fd, sendsize, recvsize)
>   
>   	slen = sizeof (struct sockaddr_storage);
>   	if (getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
> +		if (errno == ENOTSOCK) {
> +			if (libtirpc_debug_level > 3) {
> +				LIBTIRPC_DEBUG(4, ("svc_fd_create: ENOTSOCK, return directly"));
> +			}
> +			return ret;
> +		}
>   		warnx("svc_fd_create: could not retrieve local addr");
>   		goto freedata;
>   	}
diff mbox series

Patch

diff --git a/src/svc_vc.c b/src/svc_vc.c
index 3dc8a75..438cbc5 100644
--- a/src/svc_vc.c
+++ b/src/svc_vc.c
@@ -59,6 +59,7 @@ 
 #include <rpc/rpc.h>
 
 #include "rpc_com.h"
+#include "debug.h"
 
 #include <getpeereid.h>
 
@@ -232,6 +233,12 @@  svc_fd_create(fd, sendsize, recvsize)
 
 	slen = sizeof (struct sockaddr_storage);
 	if (getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
+		if (errno == ENOTSOCK) {
+			if (libtirpc_debug_level > 3) {
+				LIBTIRPC_DEBUG(4, ("svc_fd_create: ENOTSOCK, return directly"));
+			}
+			return ret;
+		}
 		warnx("svc_fd_create: could not retrieve local addr");
 		goto freedata;
 	}