DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] pipeline: fix build with glibc < 2.26
@ 2020-10-02  8:28 David Marchand
  2020-10-02 10:38 ` Dumitrescu, Cristian
  0 siblings, 1 reply; 3+ messages in thread
From: David Marchand @ 2020-10-02  8:28 UTC (permalink / raw)
  To: dev; +Cc: Cristian Dumitrescu

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 <david.marchand@redhat.com>
---
 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);
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] pipeline: fix build with glibc < 2.26
  2020-10-02  8:28 [dpdk-dev] [PATCH] pipeline: fix build with glibc < 2.26 David Marchand
@ 2020-10-02 10:38 ` Dumitrescu, Cristian
  2020-10-02 11:50   ` David Marchand
  0 siblings, 1 reply; 3+ messages in thread
From: Dumitrescu, Cristian @ 2020-10-02 10:38 UTC (permalink / raw)
  To: David Marchand; +Cc: dev



> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, October 2, 2020 9:29 AM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Subject: [PATCH] pipeline: fix build with glibc < 2.26
> 
> 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 <david.marchand@redhat.com>
> ---
>  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);
> 
> --
> 2.23.0


Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] pipeline: fix build with glibc < 2.26
  2020-10-02 10:38 ` Dumitrescu, Cristian
@ 2020-10-02 11:50   ` David Marchand
  0 siblings, 0 replies; 3+ messages in thread
From: David Marchand @ 2020-10-02 11:50 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Dumitrescu, Cristian

On Fri, Oct 2, 2020 at 12:38 PM Dumitrescu, Cristian
<cristian.dumitrescu@intel.com> wrote:
> > -----Original Message-----
> > From: David Marchand <david.marchand@redhat.com>
> > Sent: Friday, October 2, 2020 9:29 AM
> > To: dev@dpdk.org
> > Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> > Subject: [PATCH] pipeline: fix build with glibc < 2.26
> >
> > 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 <david.marchand@redhat.com>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

Applied.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-02 11:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02  8:28 [dpdk-dev] [PATCH] pipeline: fix build with glibc < 2.26 David Marchand
2020-10-02 10:38 ` Dumitrescu, Cristian
2020-10-02 11:50   ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).