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