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.129.124]) by sourceware.org (Postfix) with ESMTPS id 111F23858D38 for ; Mon, 28 Aug 2023 13:21:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 111F23858D38 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=1693228885; 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=+zO63zdDDf6hkbOesuFSYXAzRZwtrvar6S71Yui1Nqg=; b=V7uPLyxd0lKZMPGQ6iE7PJqdnDu+AEot9Yva+D12vl4KFXPcQHbQW2wLye4cHY3aYZkqtv tDK2nwyMMa1KiSgQbbo6N1FXCsW8clot70TbLAeIctdATeGWPPIIJNxo+TmxPi/YG4I3bW 9NAJX43/RKBM8fdre2w28Hu+p+LNHQk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-M7LKhgJWPT2UXDbZqqptRw-1; Mon, 28 Aug 2023 09:21:24 -0400 X-MC-Unique: M7LKhgJWPT2UXDbZqqptRw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 042DF85CCE2 for ; Mon, 28 Aug 2023 13:21:24 +0000 (UTC) Received: from oak (unknown [10.22.33.147]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1AD35CC01 for ; Mon, 28 Aug 2023 13:21:23 +0000 (UTC) Date: Mon, 28 Aug 2023 09:21:22 -0400 From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Subject: Re: [PATCH] getpw: Get rid of alloca Message-ID: <20230828132122.GV3849957@oak> References: <20230707200400.378096-1-josimmon@redhat.com> <20230810134547.GI3849957@oak> MIME-Version: 1.0 In-Reply-To: <20230810134547.GI3849957@oak> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=-11.8 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: Ping. On Thu, Aug 10, 2023 at 09:45:47AM -0400, Joe Simmons-Talbott via Libc-alpha wrote: > 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 > > >