DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/1] lib/librte_cmdline: fix added checking return value
@ 2016-05-16 15:18 Marcin Kerlin
  2016-05-17  8:36 ` [dpdk-dev] [PATCH v2] cmdline: check return value at initialization Olivier Matz
  0 siblings, 1 reply; 3+ messages in thread
From: Marcin Kerlin @ 2016-05-16 15:18 UTC (permalink / raw)
  To: olivier.matz; +Cc: dev, Marcin Kerlin

Unchecked return value: value returned from a function rdline_init is 
not checked, fix added checking return value and in the case of failure
frees memory and return null pointer.

Fixes: af75078fece3 ("first public release")
Coverity ID 13204

Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
---
 lib/librte_cmdline/cmdline.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index c405878..a9c47be 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -130,6 +130,7 @@ struct cmdline *
 cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 {
 	struct cmdline *cl;
+	int ret;
 
 	if (!ctx || !prompt)
 		return NULL;
@@ -142,8 +143,13 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 	cl->s_out = s_out;
 	cl->ctx = ctx;
 
-	rdline_init(&cl->rdl, cmdline_write_char,
-		    cmdline_valid_buffer, cmdline_complete_buffer);
+	ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
+			cmdline_complete_buffer);
+	if (ret != 0) {
+		free(cl);
+		return NULL;
+	}
+
 	cl->rdl.opaque = cl;
 	cmdline_set_prompt(cl, prompt);
 	rdline_newline(&cl->rdl, cl->prompt);
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2] cmdline: check return value at initialization
  2016-05-16 15:18 [dpdk-dev] [PATCH 1/1] lib/librte_cmdline: fix added checking return value Marcin Kerlin
@ 2016-05-17  8:36 ` Olivier Matz
  2016-05-19 12:26   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Matz @ 2016-05-17  8:36 UTC (permalink / raw)
  To: dev; +Cc: marcinx.kerlin

From: Marcin Kerlin <marcinx.kerlin@intel.com>

The value returned by rdline_init() was not checked in cmdline_new().
On error, free the allocated memory and return NULL.

This condition should not happen today, but it's safer to do the check
in case rdline_init() is updated.

Fixes: af75078fece3 ("first public release")
Coverity ID 13204

Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---

Hi Marcin,

I updated the commit log and title to be clearer.

Regards,
Olivier


v1 -> v2
  rework title and commit log

 lib/librte_cmdline/cmdline.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index c405878..a9c47be 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -130,6 +130,7 @@ struct cmdline *
 cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 {
 	struct cmdline *cl;
+	int ret;
 
 	if (!ctx || !prompt)
 		return NULL;
@@ -142,8 +143,13 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 	cl->s_out = s_out;
 	cl->ctx = ctx;
 
-	rdline_init(&cl->rdl, cmdline_write_char,
-		    cmdline_valid_buffer, cmdline_complete_buffer);
+	ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
+			cmdline_complete_buffer);
+	if (ret != 0) {
+		free(cl);
+		return NULL;
+	}
+
 	cl->rdl.opaque = cl;
 	cmdline_set_prompt(cl, prompt);
 	rdline_newline(&cl->rdl, cl->prompt);
--
2.8.0.rc3

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

* Re: [dpdk-dev] [PATCH v2] cmdline: check return value at initialization
  2016-05-17  8:36 ` [dpdk-dev] [PATCH v2] cmdline: check return value at initialization Olivier Matz
@ 2016-05-19 12:26   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2016-05-19 12:26 UTC (permalink / raw)
  To: Olivier Matz, marcinx.kerlin; +Cc: dev

2016-05-17 10:36, Olivier Matz:
> From: Marcin Kerlin <marcinx.kerlin@intel.com>
> 
> The value returned by rdline_init() was not checked in cmdline_new().
> On error, free the allocated memory and return NULL.
> 
> This condition should not happen today, but it's safer to do the check
> in case rdline_init() is updated.
> 
> Fixes: af75078fece3 ("first public release")
> Coverity ID 13204
> 
> Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> ---
> 
> Hi Marcin,
> 
> I updated the commit log and title to be clearer.

Applied, thanks

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

end of thread, other threads:[~2016-05-19 12:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-16 15:18 [dpdk-dev] [PATCH 1/1] lib/librte_cmdline: fix added checking return value Marcin Kerlin
2016-05-17  8:36 ` [dpdk-dev] [PATCH v2] cmdline: check return value at initialization Olivier Matz
2016-05-19 12:26   ` Thomas Monjalon

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).