94084c
commit 7b5d433fd097b8ed74e458eca33597290e07b974
94084c
Author: Florian Weimer <fweimer@redhat.com>
94084c
Date:   Mon Jan 17 10:21:34 2022 +0100
94084c
94084c
    CVE-2022-23219: Buffer overflow in sunrpc clnt_create for "unix" (bug 22542)
94084c
    
94084c
    Processing an overlong pathname in the sunrpc clnt_create function
94084c
    results in a stack-based buffer overflow.
94084c
    
94084c
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
94084c
    (cherry picked from commit 226b46770c82899b555986583294b049c6ec9b40)
94084c
94084c
diff --git a/sunrpc/clnt_gen.c b/sunrpc/clnt_gen.c
94084c
index 13ced8994e49d4ee..b44357cd88e60599 100644
94084c
--- a/sunrpc/clnt_gen.c
94084c
+++ b/sunrpc/clnt_gen.c
94084c
@@ -57,9 +57,13 @@ clnt_create (const char *hostname, u_long prog, u_long vers,
94084c
 
94084c
   if (strcmp (proto, "unix") == 0)
94084c
     {
94084c
-      memset ((char *)&sun, 0, sizeof (sun));
94084c
-      sun.sun_family = AF_UNIX;
94084c
-      strcpy (sun.sun_path, hostname);
94084c
+      if (__sockaddr_un_set (&sun, hostname) < 0)
94084c
+	{
94084c
+	  struct rpc_createerr *ce = &get_rpc_createerr ();
94084c
+	  ce->cf_stat = RPC_SYSTEMERROR;
94084c
+	  ce->cf_error.re_errno = errno;
94084c
+	  return NULL;
94084c
+	}
94084c
       sock = RPC_ANYSOCK;
94084c
       client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
94084c
       if (client == NULL)