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 D91E13858D35 for ; Tue, 26 Sep 2023 13:55:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D91E13858D35 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=1695736533; 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=r3v2vJWJJ0XK5YlQOpZjfD/RlXWXsBF6QTqgJ999pvY=; b=Ktta7dyTBfsUC3bZywCAsIEguh60ekZ77g4ZYVOmBpEswfisYMD37AhSBj4SqSkXh6Q0Ic M9l96OG+qkxNS9UyCl6bk+1OHEIU1oH2Mc1GxpUoNRSkbCj667b+xB/n0/POkOkPh+3WP5 X/Xv0/NXeqRLqUu/aEGFO1BMPjq2wTA= Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-XRV84lqVNiWDkFIltIujCg-1; Tue, 26 Sep 2023 09:55:32 -0400 X-MC-Unique: XRV84lqVNiWDkFIltIujCg-1 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-45285ddac4bso4111551137.1 for ; Tue, 26 Sep 2023 06:55:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695736531; x=1696341331; 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=r3v2vJWJJ0XK5YlQOpZjfD/RlXWXsBF6QTqgJ999pvY=; b=Rch3ULVDRqjCziUSuBTnb0bzZluZ1F3sYJvuEsE96Bz22Mi5m/xO5kdaZnTYHX2bTo a4/O42XrmsL9eWr7XNWUHf5YM6ZSUnVGzo38rvhPre6oD3jQVRK5+ydleueSvxEFWweP TuGPzs2U93rT5A4wmNz0cKz4xEIUa3PBfuNoe7YOiSesxJexalwk48H4kkc3uohV6JZ+ teEfTq6InxYkY8h0czK3W6+NOnAiQ8VCTF4QQDNP2S/sWXjEK2jNXZOIDHHWS/tO67lr 9hGXJJ+V0MzbtBcosW9Z/+aV6XRGOxRYZMtZnV2bk3drHIWfwQL01RMdTKKad6A1PqpQ A4Tw== X-Gm-Message-State: AOJu0YxUyfeXrY2uiO+vzPOhk3vLiQX/1asZRpAGs4SAVlXlHWwVo17H l38oIfpneqPRqGeQlgvtO4sL3AHZiWX78QJ4mLl8+qy70Fyn5yJaZreds3wXaeCqSS7PUkAnN8c TMX1q60cYKD42fLrOADfsZnPwsuKgm1DdAuD0p0fCiEweZKc1PJwNzg+YNsAmBXUKYk5dJoYYMb sXby1g X-Received: by 2002:a67:f842:0:b0:452:6a39:ab1c with SMTP id b2-20020a67f842000000b004526a39ab1cmr6046514vsp.12.1695736530775; Tue, 26 Sep 2023 06:55:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbo9U6WAVPcRnAXwVwZCE34otGDmt2cwU92PquIbmnwkaIrOOQwfWuEqeJbtEqg7znEjxJug== X-Received: by 2002:a67:f842:0:b0:452:6a39:ab1c with SMTP id b2-20020a67f842000000b004526a39ab1cmr6046495vsp.12.1695736530465; Tue, 26 Sep 2023 06:55:30 -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 vr25-20020a05620a55b900b0077434d0f06esm1508024qkn.52.2023.09.26.06.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 06:55:29 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] nss: Get rid of alloca usage in makedb's write_output. Date: Tue, 26 Sep 2023 09:54:48 -0400 Message-ID: <20230926135528.3517253-1-josimmon@redhat.com> X-Mailer: git-send-email 2.41.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.6 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,RCVD_IN_MSPIKE_H3,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: Replace alloca usage with a scratch_buffer. --- nss/makedb.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nss/makedb.c b/nss/makedb.c index 48c8fe1333..c2779d9d9e 100644 --- a/nss/makedb.c +++ b/nss/makedb.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -739,7 +740,16 @@ write_output (int fd) struct nss_db_header *header; uint64_t file_offset = (sizeof (struct nss_db_header) + (ndatabases * sizeof (header->dbs[0]))); - header = alloca (file_offset); + struct scratch_buffer sbuf; + scratch_buffer_init (&sbuf); + + + if (!scratch_buffer_set_array_size (&sbuf, 1, file_offset)) + { + error (0, errno, gettext ("failed to allocate memory")); + return EXIT_FAILURE; + } + header = sbuf.data; header->magic = NSS_DB_MAGIC; header->ndbs = ndatabases; @@ -802,6 +812,7 @@ write_output (int fd) assert (iov_nelts <= INT_MAX); if (writev (fd, iov, iov_nelts) != keydataoffset) { + scratch_buffer_free (&sbuf); error (0, errno, gettext ("failed to write new database file")); return EXIT_FAILURE; } @@ -810,6 +821,7 @@ write_output (int fd) DIAG_POP_NEEDS_COMMENT; #endif + scratch_buffer_free (&sbuf); return EXIT_SUCCESS; } -- 2.39.2