From patchwork Fri Oct 2 08:28:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 79525 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 02065A04BA; Fri, 2 Oct 2020 10:28:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 48F741D59B; Fri, 2 Oct 2020 10:28:43 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 83DA91D53B for ; Fri, 2 Oct 2020 10:28:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601627320; 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=6aPEcfkU1kgz6ZH+r4PCWJgfmgod1NCv7o1WhhqHj3I=; b=WeCRZe9aj8vzp4+1tlkqvu5IV5bbUVKyZgRWQEG+Gv61GTkGbbGXKoyqJL04ATPUkvEycx QjXNxvB2VMgMJHgEkTDKEBmQgXho9wm0/kpdkyPrepkWOyv63T0itOT/OoP92iiBp/Dj4n X11En8vqBowNsy+uYrkw1s15z06NJEk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-396-Xd0OAQHzOzi1kajjqSDj9Q-1; Fri, 02 Oct 2020 04:28:38 -0400 X-MC-Unique: Xd0OAQHzOzi1kajjqSDj9Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A2BB186DD26; Fri, 2 Oct 2020 08:28:37 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65E355578C; Fri, 2 Oct 2020 08:28:36 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Cristian Dumitrescu Date: Fri, 2 Oct 2020 10:28:31 +0200 Message-Id: <20201002082831.5352-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH] pipeline: fix build with glibc < 2.26 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" reallocarray has been introduced in glibc 2.26 but we still support glibc >= 2.7. Simply replace with realloc, as the considered sizes are unlikely to overflow. """ The reallocarray() function changes the size of the memory block pointed to by ptr to be large enough for an array of nmemb elements, each of which is size bytes. It is equivalent to the call realloc(ptr, nmemb * size); However, unlike that realloc() call, reallocarray() fails safely in the case where the multiplication would overflow. If such an over‐ flow occurs, reallocarray() returns NULL, sets errno to ENOMEM, and leaves the original block of memory unchanged. """ Fixes: 3ca60ceed79a ("pipeline: add SWX pipeline specification file") Signed-off-by: David Marchand Acked-by: Cristian Dumitrescu --- lib/librte_pipeline/rte_swx_pipeline_spec.c | 25 +++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/librte_pipeline/rte_swx_pipeline_spec.c b/lib/librte_pipeline/rte_swx_pipeline_spec.c index d72badd03d..95de8f983d 100644 --- a/lib/librte_pipeline/rte_swx_pipeline_spec.c +++ b/lib/librte_pipeline/rte_swx_pipeline_spec.c @@ -213,9 +213,8 @@ struct_block_parse(struct struct_spec *s, return -ENOMEM; } - new_fields = reallocarray(s->fields, - s->n_fields + 1, - sizeof(struct rte_swx_field_params)); + new_fields = realloc(s->fields, + (s->n_fields + 1) * sizeof(struct rte_swx_field_params)); if (!new_fields) { free(name); @@ -452,9 +451,8 @@ action_block_parse(struct action_spec *s, return -ENOMEM; } - new_instructions = reallocarray(s->instructions, - s->n_instructions + 1, - sizeof(char *)); + new_instructions = realloc(s->instructions, + (s->n_instructions + 1) * sizeof(char *)); if (!new_instructions) { free(instr); @@ -620,9 +618,8 @@ table_key_block_parse(struct table_spec *s, return -ENOMEM; } - new_fields = reallocarray(s->params.fields, - s->params.n_fields + 1, - sizeof(struct rte_swx_match_field_params)); + new_fields = realloc(s->params.fields, + (s->params.n_fields + 1) * sizeof(struct rte_swx_match_field_params)); if (!new_fields) { free(name); @@ -700,9 +697,8 @@ table_actions_block_parse(struct table_spec *s, return -ENOMEM; } - new_action_names = reallocarray(s->params.action_names, - s->params.n_actions + 1, - sizeof(char *)); + new_action_names = realloc(s->params.action_names, + (s->params.n_actions + 1) * sizeof(char *)); if (!new_action_names) { free(name); @@ -1019,9 +1015,8 @@ apply_block_parse(struct apply_spec *s, return -ENOMEM; } - new_instructions = reallocarray(s->instructions, - s->n_instructions + 1, - sizeof(char *)); + new_instructions = realloc(s->instructions, + (s->n_instructions + 1) * sizeof(char *)); if (!new_instructions) { free(instr);