From patchwork Thu Jun 8 14:32:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 70789 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 865943858C62 for ; Thu, 8 Jun 2023 14:33:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 865943858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686234790; bh=pxU00LVpFI1dzMlytwIel9TNyxag0t2BMXoXU41osLw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=kWrAZmqZJ8uuI5Y8UjEmirNCJbOiWNuWMCdVTMZGZ1RW094qialrmi5CoQyY1hl7t 60YpO4WTGl8Nj+3xR50cQjL3lvNAqCXup3YS0glQXWpBrMTY6dJjRNvK44m+yVP6fg 27woowk0mZSC3Uywb0Gq4dlA1BBOgqvStumbxsi0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 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) 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 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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;