From patchwork Thu Sep 28 13:05:37 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: 76835 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 0C8A43861849 for ; Thu, 28 Sep 2023 13:06:09 +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 A7BFA3858C01 for ; Thu, 28 Sep 2023 13:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7BFA3858C01 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=1695906354; 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=S/eXo3Af722uhdosV5CQE2Y0VcK8ikh465qkh0XvqJ4=; b=JbH/dwEmkyZN3C0BlQFwXOlP5vaP3dk7vVRv+hzSZFMRz8bcn3ktxuyDUfVqFNdtlD9yYY B2xvtaIMRmXbBOkTCAGERgT+4E4qtQ3gJiZz31hnvyftJbyd8wMt1UMe4lTXV7uLX0Fr+k FKS/ycm4WxF/J5sDNzkcpNwG8dahf1o= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-GG_CMLaeMYmI41A7H5wg_A-1; Thu, 28 Sep 2023 09:05:52 -0400 X-MC-Unique: GG_CMLaeMYmI41A7H5wg_A-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-775869cf2f5so12223585a.1 for ; Thu, 28 Sep 2023 06:05:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695906352; x=1696511152; 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=S/eXo3Af722uhdosV5CQE2Y0VcK8ikh465qkh0XvqJ4=; b=FUAOqwkEl7G7iS7QPLGGyTBaPIgYPeRSlfqYJ/jqR2EGdjLUPrITbKYAti8JXDinNo rqmBAUynkCm23iX36SYaMqkgmL3PDHfZylDAlU0OlGJEr5tFOkkOLm/xgAM6kaU1vHm4 m1R1zTu1O2bhY+mRCVvFuieLY6yvPW41Ht3HwsPGcKcBa8hjOfA/Pqps8fDCn/suKudu ZbJ2Vo6xxOuaoe4HQW5hkHWCs/T2FNYAvCYkPaYylWR78OLal4dQEgnob5X7ZPhRm1Vm c7fVLdXDI38weefX5NK0+jZLDmERjtOZQCAq5gIljnSwHXyUIrndUKmVSorsOuPQNWB3 in3w== X-Gm-Message-State: AOJu0YwYTGnLMfwbXL5cKTIR8kiI4tGDt/RqjiZb6IRa7zi/6lvOfUig DxuPWVr0oQ1ecpupyFzOroEu9DyQUnTSGD3IO+EZ/um/s4tLj6lnIrk+XbhUwXni5KJ+LN4hstv 11xWrZmXRaW+afUuBaQz621dOT4HVjASXvyV+LxVDOOemZHWc8iozlLD8/snfrVUVtpLYP9bG3c 4KgIWu X-Received: by 2002:a05:620a:1a21:b0:76c:ea67:38e4 with SMTP id bk33-20020a05620a1a2100b0076cea6738e4mr1099841qkb.12.1695906351952; Thu, 28 Sep 2023 06:05:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2kc0jNPhQluIzbbZAiy9G0L4JrsxTT55fjc2r1/jHK+gBvl0CtYVjYdBSBAUSvmkWy/H8AQ== X-Received: by 2002:a05:620a:1a21:b0:76c:ea67:38e4 with SMTP id bk33-20020a05620a1a2100b0076cea6738e4mr1099809qkb.12.1695906351598; Thu, 28 Sep 2023 06:05:51 -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 d2-20020a05620a166200b00767721aebc0sm2196303qko.32.2023.09.28.06.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:05:50 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v3] nss: Get rid of alloca usage in db-XXX Date: Thu, 28 Sep 2023 09:05:37 -0400 Message-ID: <20230928130548.1203408-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.7 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. --- Changes to v2: * fix '\' alignment. * set errnop to errno rather than ENOMEM nss/nss_db/db-XXX.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c index 0ce730db5a..8f174fc8ea 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,14 @@ enum nss_status \ else \ { \ const size_t size = (keysize) + 1; \ - key = alloca (size); \ + if (!scratch_buffer_set_array_size (&sbuf, 1, size)) \ + { \ + *errnop = errno; \ + H_ERRNO_SET (NETDB_INTERNAL); \ + status = NSS_STATUS_TRYAGAIN; \ + goto out; \ + } \ + key = sbuf.data; \ \ KEYPRINTF keypattern; \ } \ @@ -216,6 +226,7 @@ enum nss_status \ \ out: \ internal_endent (&state); \ + scratch_buffer_free (&sbuf); \ \ return status; \ }