From patchwork Thu Sep 28 14:11:14 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: 76847 X-Patchwork-Delegate: arjun.is@lostca.se 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 2C44F3858433 for ; Thu, 28 Sep 2023 14:12:14 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id A19F3386180B for ; Thu, 28 Sep 2023 14:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A19F3386180B 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=1695910290; 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=c75LDFPzEeiQuWx+vrcxT0GUJ71h2txMFJzqzYTOoDE=; b=ZpVNbpJL35cKj7Fr8e3n/XOqlb86YF0sBZrhMYWbc49IZGOBqrCWStzRKqCwmKnglTGFLQ E/mAe/TtYwna9504J+g55C31gXDZsxqkv7tubXxJMRq3IMTH829jDfuzmQbwJCzzo1zWEB P4oeHtTz+MBo4VJ7Dzk5QcaEHtZfKDI= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-0VhQ_3O0PWq8Fk2BnXmTzQ-1; Thu, 28 Sep 2023 10:11:29 -0400 X-MC-Unique: 0VhQ_3O0PWq8Fk2BnXmTzQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-418145b6579so129493301cf.2 for ; Thu, 28 Sep 2023 07:11:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695910288; x=1696515088; 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=c75LDFPzEeiQuWx+vrcxT0GUJ71h2txMFJzqzYTOoDE=; b=rzDgaMhAzTCYiuHUxTOOZcbURMsRjDgZ6M22fixm9WwwqjnPzQa/r5ztuqM4EcUEe6 W586rcwh4I7yEnkxEd36cvttuGfEb9fSSHgpA6ePpf/JwCTIiXXjhYtM/UCPWy8sXEmh /WPAfBsyPvhCEvocqpc0gg1X83VNgerJTOzBVO70y3OBl8BA6xiilYebVPlS4oN7h/yD fVGz4tVpfxPhKhrpalVRWdc5K/2++tIIk5GAot2vpH+V5UZFOyX0ZqCZCauV5WF/dzA3 5ULWhv7P6mxKR/A3AfxzWvsYlYKWF8Fa+NfrrEYKK6uLe8f4114jGk484D7wpATc367x U1EQ== X-Gm-Message-State: AOJu0YzxU0f0+INXZ/qdwgFDyDePMVxAfaj9lrESWE7nf1ORbjLY/p8q 6NMYTQgQbiTV2mukLTUaIekirTHUgwgc+/eblxk4G8UxF1hdff95pDfOYrFqRwAegJxQsFWH15+ S2qVG1sKvXjrVe/0LnLTWzKEVIsBaDSyhJCE71F1LwD9OdF3DG4+7P++Ygn+49O0VfBYgtUiu/g gMxMD1 X-Received: by 2002:ac8:59c3:0:b0:410:a088:38f5 with SMTP id f3-20020ac859c3000000b00410a08838f5mr1414618qtf.4.1695910288411; Thu, 28 Sep 2023 07:11:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHNARNNs0KQMykx+787bK9K/8EidVCR8dh8luIpxA7tNpuEwDen0gv9Mi9XGnTJpDlOJaPBg== X-Received: by 2002:ac8:59c3:0:b0:410:a088:38f5 with SMTP id f3-20020ac859c3000000b00410a08838f5mr1414594qtf.4.1695910288071; Thu, 28 Sep 2023 07:11:28 -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 g2-20020ac870c2000000b004197079f2f8sm323429qtp.64.2023.09.28.07.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:11:27 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2] nss: Get rid of alloca usage in makedb's write_output. Date: Thu, 28 Sep 2023 10:11:14 -0400 Message-ID: <20230928141125.600816-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 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Replace alloca usage with a scratch_buffer. Reviewed-by: Arjun Shankar --- Changes to v1: * move scratch_buffer_free after the call to error (). nss/makedb.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nss/makedb.c b/nss/makedb.c index 48c8fe1333..67c3c4c893 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; @@ -803,6 +813,7 @@ write_output (int fd) if (writev (fd, iov, iov_nelts) != keydataoffset) { error (0, errno, gettext ("failed to write new database file")); + scratch_buffer_free (&sbuf); return EXIT_FAILURE; } @@ -810,6 +821,7 @@ write_output (int fd) DIAG_POP_NEEDS_COMMENT; #endif + scratch_buffer_free (&sbuf); return EXIT_SUCCESS; }