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 9079B3858C2C for ; Thu, 1 Jun 2023 19:58:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9079B3858C2C 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=1685649504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UpSX+GeGAFHPzwENUP0S8RH0EdtyOFI30yIIlQpt89A=; b=Y/z9tL6/H0iAaTVJGZqjGdh74PulBRnGSZy60wCvFHiQIUF1UfNmwIA3Ip82Be8ixDLuq9 8dBBEnV0osb5yX1o2RAKUk8Xjn2ETQDKmZtEFmcd6ruckI7fXCXm1/MksK4oVKCQMB5n5Q iP0NYXvfLoPhpPj11E5DEviGCQ2p3a0= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-412-e0sd7_oKO7m4WgaC_xuMPQ-1; Thu, 01 Jun 2023 15:58:23 -0400 X-MC-Unique: e0sd7_oKO7m4WgaC_xuMPQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-75cac31d7c3so138949685a.3 for ; Thu, 01 Jun 2023 12:58:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685649502; x=1688241502; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UpSX+GeGAFHPzwENUP0S8RH0EdtyOFI30yIIlQpt89A=; b=U4lPjENJqfVCd3kdNvF9b0zRKVpGa61VaeXaoHrJ82DCuTaUtclsrNJDdO91+7ebnJ sL2Gobqrp1GrriE47iVbess7p7Taq6JnJ2wDbF77En1xH2yLUqOGks18SbP/kVwrQ/zc TLyn64Mq4rlpRm5ClBYX+tTGI9JxXLoIVuSpuKfxpJ0iMC0DFTamW9+7XY8a+hJo9m0T WnRT5bOKAs/taAzRZr/dHBFISPABqPwQJuk+PuDk+00wHD7MCdJsnxlxCTpu7h7RAB9Y 2LxpJNJfg3hmb248VxNwYCJslfNuK9DtNdFRP5lXa6MFZNQ5deXWrMEIT4TwOuog02g7 TPpQ== X-Gm-Message-State: AC+VfDxupbeEV8Sq+BOOZWzktxeJ09pas2GbcxepgYe75wCDNsyZwADN mGUDLaxL96VneFTm8BqTUETc2XRMKDU4LclmIEMxd/mAdtjTr7zI3lKoUU0wzmc+MvGsxzITY0e tGG9BQlVkC79Ht3kN0W4vqtG0odG0tXnuSHx059dsKrgS2gPYzJ2QXZ0bsgboEu0UyLbYN1ai5l e8qw9W X-Received: by 2002:a05:620a:298a:b0:75b:23a1:3f8 with SMTP id r10-20020a05620a298a00b0075b23a103f8mr13691969qkp.14.1685649502198; Thu, 01 Jun 2023 12:58:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4OrzmdegDIh1DZoFqR9jxcVX5bZL6VzS33H2nSibUiwpM2IuqvEctU+23Yvuno+8zcVv3KfQ== X-Received: by 2002:a05:620a:298a:b0:75b:23a1:3f8 with SMTP id r10-20020a05620a298a00b0075b23a103f8mr13691949qkp.14.1685649501800; Thu, 01 Jun 2023 12:58:21 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id pj27-20020a05620a1d9b00b0075c9e048b19sm7128166qkn.29.2023.06.01.12.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 12:58:21 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] grantpt: Get rid of alloca Date: Thu, 1 Jun 2023 15:58:17 -0400 Message-Id: <20230601195817.3251303-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: Replace alloca with a scratch_buffer to avoid potential stack overflows. --- sysdeps/unix/grantpt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c index 38fce52576..e5d2390bf2 100644 --- a/sysdeps/unix/grantpt.c +++ b/sysdeps/unix/grantpt.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -147,7 +148,14 @@ grantpt (int fd) /* `sysconf' does not support _SC_GETGR_R_SIZE_MAX. Try a moderate value. */ grbuflen = 1024; - grtmpbuf = (char *) __alloca (grbuflen); + struct scratch_buffer sbuf; + scratch_buffer_init (&sbuf); + if (!scratch_buffer_set_array_size (&sbuf, 1, grbuflen)) + { + retval -1; + goto cleanup; + } + grtmpbuf = sbuf.data; __getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p); if (p != NULL) tty_gid = p->gr_gid; @@ -255,6 +263,8 @@ grantpt (int fd) if (buf != _buf) free (buf); + scratch_buffer_free(sbuf); + return retval; } libc_hidden_def (grantpt) -- 2.39.2