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 4A3DE3858C62 for ; Thu, 8 Jun 2023 14:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A3DE3858C62 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=1686234767; 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=pxU00LVpFI1dzMlytwIel9TNyxag0t2BMXoXU41osLw=; b=JNyZGhtyJt+FrUaGNv7XWSAiCxuyIZKZndNTaJzCRg6Ck4z7gFRG8LwVXani/eToayOJxD lDW9AbfaBFwWONOPDE0VX6Dj/SRFAmc5pFCJv/NpoaXKJZhS6e7h5XwVi3PXFbYpgSaNvi 6T9kH8KhijKxR/J5TfXPz8dtSclbl0I= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-HpZl0UzgPRetAvdp-ZyMaA-1; Thu, 08 Jun 2023 10:32:43 -0400 X-MC-Unique: HpZl0UzgPRetAvdp-ZyMaA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-62b3d4accd8so10083056d6.1 for ; Thu, 08 Jun 2023 07:32:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234763; x=1688826763; 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=pxU00LVpFI1dzMlytwIel9TNyxag0t2BMXoXU41osLw=; b=LR+ofQMvp9/5YsPnljzOxhabpFrc1jBB552SLmVPhLcs9GhQRSZn+r9dVf/P5BXgLt swtn+pupKl6HrR3kuQIN+WLYZ/U0mv+4dbcdlfRxaQ9uCKz5639faZd5t2e5PRpLA+/b Ea5t5f+7LN3uEMLn17e7Bt9jzBhanEgGvdYA/U/aSThmYiBOzVQCmDWfk5DR4t6XJWfz KL2lK/AZ3eJMYP4VHdwujADsrDR3TaFS4uV8gIkboJYMjIP/THjUkIJaEeKS9QWe1Ouu +mVLJsvFXR/c//Y4+MD01LZMclIGMjXwJw7moEaUpEa3kw2cKv+HqiyswJOf59XyiDGm Ll6A== X-Gm-Message-State: AC+VfDxXayAp2TulY0LV6aH0vyg5eE/Kzo3F2aMOfhIR5VkZRRsc4NsB lMLJhFArBpLxL4UNSyRNRBsF55cJc6ZZO+gMtrLQP+iYiw648Lqc28cMGw+TUWufGIc3+7hyhRD N2kSSDrzeo/pove+Dc9YU X-Received: by 2002:a05:6214:501c:b0:62b:3d13:2db4 with SMTP id jo28-20020a056214501c00b0062b3d132db4mr2384813qvb.43.1686234762917; Thu, 08 Jun 2023 07:32:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+3a6hVwxQ4LE1SBgxhtjoc1P3S7NkFsN5gYtHPV4urbQXVWFRel1neSGjIqgEg1ZI7PoNsw== X-Received: by 2002:a05:6214:501c:b0:62b:3d13:2db4 with SMTP id jo28-20020a056214501c00b0062b3d132db4mr2384789qvb.43.1686234762626; Thu, 08 Jun 2023 07:32:42 -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 o16-20020a056214109000b006261e6a88c7sm440047qvr.36.2023.06.08.07.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:32:42 -0700 (PDT) From: Joe Simmons-Talbott To: Samuel Thibault , Sergey Bugaev , libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v3] grantpt: Get rid of alloca Date: Thu, 8 Jun 2023 10:32:38 -0400 Message-Id: <20230608143238.4002713-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. --- Changes to v2: * Don't set retval in scratch_buffer resize failure case since it's already set from initialization. sysdeps/unix/grantpt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c index 38fce52576..6818ee6369 100644 --- a/sysdeps/unix/grantpt.c +++ b/sysdeps/unix/grantpt.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -147,10 +148,16 @@ 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)) + goto cleanup; + grtmpbuf = sbuf.data; __getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p); if (p != NULL) tty_gid = p->gr_gid; + + scratch_buffer_free(&sbuf); } gid_t gid = tty_gid == -1 ? __getgid () : tty_gid; -- 2.39.2