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