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