From patchwork Wed Sep 27 15:38:29 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: 76774 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 E989A386190C for ; Wed, 27 Sep 2023 15:38:49 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 6973A385559E for ; Wed, 27 Sep 2023 15:38:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6973A385559E 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=1695829116; 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=yOPbZhuBGbUiqy2zh+9AwVD4ZFw6blM1QN/Aj+5Q2F4=; b=dbqNm33o8jFUUyk77NhqI6fa6k6iAMB6Nj2iPyZ9AXatODFvwDfBkwp/0aMEKsappNYgBc L/AAtcCus9t9tQaM3IKDWeTeYVH51hviv5tk3XQ3q1OO4XVo5REflHqJFnPJap0GjpOxcE ahtZAy8S2zHhnvu3u592Df1lquYWyL0= 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-357-n7ipX5wZOr2hpU31UlaHmA-1; Wed, 27 Sep 2023 11:38:35 -0400 X-MC-Unique: n7ipX5wZOr2hpU31UlaHmA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-773f7c8cbf8so1265339885a.1 for ; Wed, 27 Sep 2023 08:38:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695829114; x=1696433914; 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=yOPbZhuBGbUiqy2zh+9AwVD4ZFw6blM1QN/Aj+5Q2F4=; b=ikq9mRxnbvEgW+NShFcEGcHYXAqlR4tN3D+RQSdLgzSexxu+bYcPzf6BCk4YcdiLik +F6jrr8Y9Kcxg7kFkTBasd6G+SOEyuOXOeyf0BnYD2xIWIMCDqsjFpVi+mggWjfuBSsT 0rW8CyD+Txt+WWIKGLIrYim/IkJvU8ldvkQwHDHfoFQQgkqItd4fncTjprUCv2IduMRd LYzBTqIVAq4kMUA2Z/Gvz9Ogy+r1yO3+5mqYvOKCk40+QYN15BQkej+WWI/6kyGgOpVG 5wM0MPZQBNVJ0qsK4yNFwbta1DItM3VfMWy+At10pnxP2rskdJjBT8JTY5by9CgUNVqa 2lKQ== X-Gm-Message-State: AOJu0Yy33Hc4CQwXeaHPrIoW7i5TY7WZ8yR8AIL1K9KFkj3JRGJP9/pS xv9Cvemrz2LyHxM8nbHU7HPXQ0/nGKAD9KGjxy6qTS5HhxgsBJJ1FxlqzhBqxJeCyAIK+I0OJ16 4jg5LZy/xzUUNV3wlwTMW48olyAKze5DkHDGtYrxKzqlleqMXnu4wh9/MC19Z0h3EYQ5/n0sRWS VEMvpQ X-Received: by 2002:a05:620a:2992:b0:773:c43e:5e73 with SMTP id r18-20020a05620a299200b00773c43e5e73mr6923967qkp.25.1695829114565; Wed, 27 Sep 2023 08:38:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsFb77AxBCmFHHi38g29+nobiM0/mUF+L1AWPXS/J7m/NNZBovYdiN+a1dNhPnJmS3CdZ1+g== X-Received: by 2002:a05:620a:2992:b0:773:c43e:5e73 with SMTP id r18-20020a05620a299200b00773c43e5e73mr6923947qkp.25.1695829114265; Wed, 27 Sep 2023 08:38:34 -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 bn41-20020a05620a2ae900b00765ab6d3e81sm5206080qkb.122.2023.09.27.08.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 08:38:33 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] nss: Get rid of alloca usage in db-XXX Date: Wed, 27 Sep 2023 11:38:29 -0400 Message-ID: <20230927153831.2638026-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=-11.9 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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. --- nss/nss_db/db-XXX.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c index 0ce730db5a..2df31a8077 100644 --- a/nss/nss_db/db-XXX.c +++ b/nss/nss_db/db-XXX.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -126,6 +127,8 @@ enum nss_status \ char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO)\ { \ struct parser_data *data = (void *) buffer; \ + struct scratch_buffer sbuf; \ + scratch_buffer_init (&sbuf); \ \ if (buflen < sizeof *data) \ { \ @@ -160,7 +163,13 @@ enum nss_status \ else \ { \ const size_t size = (keysize) + 1; \ - key = alloca (size); \ + if (!scratch_buffer_set_array_size (&sbuf, 1, size)) \ + { \ + H_ERRNO_SET (NETDB_INTERNAL); \ + status = NSS_STATUS_TRYAGAIN; \ + return status; \ + } \ + key = sbuf.data; \ \ KEYPRINTF keypattern; \ } \ @@ -216,6 +225,7 @@ enum nss_status \ \ out: \ internal_endent (&state); \ + scratch_buffer_free (&sbuf); \ \ return status; \ }