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