From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5F8943858D20 for ; Thu, 10 Aug 2023 13:45:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F8943858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691675151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HWoEdUJDIXiNFDp1QR6C14PcvpwTK5lgxe0eVVcp/AI=; b=Qd6CBwp4BwPuiCoaW/XWZj/E+ViSYhpj4AENNQtFV3CfM4BhtFZTS4ivU03UBwLlhrEdVq T8Q2hG7t0OKs0GeNI38lx48FnMyYqQMnLb5SXK9JmJvuVF3WLY/O73pLpN4QR/Sn5VUjkv sSOthYYgcOIVLNdkyt8dupTzKrjspu0= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-134-jHUW6nKfOtWMduz12YILDA-1; Thu, 10 Aug 2023 09:45:48 -0400 X-MC-Unique: jHUW6nKfOtWMduz12YILDA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81FFC29DD992 for ; Thu, 10 Aug 2023 13:45:48 +0000 (UTC) Received: from oak (unknown [10.22.33.199]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AF3A2026D4B for ; Thu, 10 Aug 2023 13:45:48 +0000 (UTC) Date: Thu, 10 Aug 2023 09:45:47 -0400 From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Subject: Re: [PATCH] getpw: Get rid of alloca Message-ID: <20230810134547.GI3849957@oak> References: <20230707200400.378096-1-josimmon@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230707200400.378096-1-josimmon@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Jul 07, 2023 at 04:04:00PM -0400, Joe Simmons-Talbott wrote: > Use a scratch_buffer rather than alloca to avoid potential stack > overflow. Ping. Thanks, Joe > --- > pwd/getpw.c | 34 +++++++++++++++++++++++++++------- > 1 file changed, 27 insertions(+), 7 deletions(-) > > diff --git a/pwd/getpw.c b/pwd/getpw.c > index cf747374b8..7a27d79910 100644 > --- a/pwd/getpw.c > +++ b/pwd/getpw.c > @@ -15,8 +15,8 @@ > License along with the GNU C Library; if not, see > . */ > > -#include > #include > +#include > #include > #include > #include > @@ -34,28 +34,48 @@ __getpw (__uid_t uid, char *buf) > size_t buflen; > char *tmpbuf; > struct passwd resbuf, *p; > + int retval = 0; > + struct scratch_buffer sbuf; > + scratch_buffer_init (&sbuf); > > if (buf == NULL) > { > __set_errno (EINVAL); > - return -1; > + retval = -1; > + goto error_out; > } > > buflen = __sysconf (_SC_GETPW_R_SIZE_MAX); > - tmpbuf = alloca (buflen); > + if (!scratch_buffer_set_array_size (&sbuf, 1, buflen)) > + { > + retval = -1; > + goto error_out; > + } > + tmpbuf = sbuf.data; > > if (__getpwuid_r (uid, &resbuf, tmpbuf, buflen, &p) != 0) > - return -1; > + { > + retval = -1; > + goto error_out; > + } > > if (p == NULL) > - return -1; > + { > + retval = -1; > + goto error_out; > + } > > if (sprintf (buf, "%s:%s:%lu:%lu:%s:%s:%s", p->pw_name, p->pw_passwd, > (unsigned long int) p->pw_uid, (unsigned long int) p->pw_gid, > p->pw_gecos, p->pw_dir, p->pw_shell) < 0) > - return -1; > + { > + retval = -1; > + goto error_out; > + } > > - return 0; > +error_out: > + scratch_buffer_free (&sbuf); > + return retval; > } > weak_alias (__getpw, getpw) > > -- > 2.39.2 >