[dpdk-dev] buildtools: add null point check for calloc

Message ID 1505475188-10681-1-git-send-email-wang.yong19@zte.com.cn (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Yong Wang Sept. 15, 2017, 11:33 a.m. UTC
  In func locate_pmd_entries(), pointer 'new' returned from call to func
'calloc' may be NULL. It is dereferenced without null point check.

Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>
---
 buildtools/pmdinfogen/pmdinfogen.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon Nov. 7, 2017, 10:26 p.m. UTC | #1
15/09/2017 13:33, Yong Wang:
> In func locate_pmd_entries(), pointer 'new' returned from call to func
> 'calloc' may be NULL. It is dereferenced without null point check.
> 
> Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>

Applied, thanks
  

Patch

diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c
index e73fc76..96ccbf3 100644
--- a/buildtools/pmdinfogen/pmdinfogen.c
+++ b/buildtools/pmdinfogen/pmdinfogen.c
@@ -327,6 +327,10 @@  static int locate_pmd_entries(struct elf_info *info)
 
 	do {
 		new = calloc(sizeof(struct pmd_driver), 1);
+		if (new == NULL) {
+			fprintf(stderr, "Failed to calloc memory\n");
+			return -1;
+		}
 		new->name_sym = find_sym_in_symtab(info, "this_pmd_name", last);
 		last = new->name_sym;
 		if (!new->name_sym)
@@ -408,7 +412,8 @@  int main(int argc, char **argv)
 	}
 	parse_elf(&info, argv[1]);
 
-	locate_pmd_entries(&info);
+	if (locate_pmd_entries(&info) < 0)
+		exit(1);
 
 	if (info.drivers) {
 		output_pmd_info_string(&info, argv[2]);