Skip to contentSkip to conversation

cfgfile: fix uninitialized variable on load error

PATCH Applied Dmitriy Yakovlev 3 participants 4 messages Feb 7, 2017 – Feb 14, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfgfile: fix uninitialized variable on load error

Uninitialized scalar variable. Using uninitialized value cfg->sections[curr_section]->num_entries when calling rte_cfgfile_close.
And memory in variables cfg->sections[curr_section], sect->entries[curr_entry] maybe not equal NULL. We must decrement counters curr_section, curr_entry when failed to realloc.

Fixes eaafbad419bf ("cfgfile: library to interpret config files")
---
 lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_cfgfile/rte_cfgfile.c +4 -0
index d72052a..829109a 100644
@@ -151,6 +151,7 @@ struct rte_cfgfile *
 					sizeof(*cfg) + sizeof(cfg->sections[0])
 					* allocated_sections);
 				if (n_cfg == NULL) {
+					curr_section--;
 					printf("Error - no more memory\n");
 					goto error1;
 				}
@@ -198,6 +199,7 @@ struct rte_cfgfile *
 					sizeof(sect->entries[0]) *
 					allocated_entries);
 				if (n_sect == NULL) {
+					curr_entry--;
 					printf("Error - no more memory\n");
 					goto error1;
 				}
@@ -233,6 +235,8 @@ struct rte_cfgfile *
 
 error1:
 	cfg->num_sections = curr_section + 1;
+	if (curr_section >= 0)
+		cfg->sections[curr_section]->num_entries = curr_entry + 1;
 	rte_cfgfile_close(cfg);
 error2:
 	fclose(f);
Signature · 1 line
1.9.1
#1 lore raw

Ping Cristian

2017-02-07 05:51, Dmitriy Yakovlev:

Quoted 6 lines

Uninitialized scalar variable. Using uninitialized value cfg->sections[curr_section]->num_entries when calling rte_cfgfile_close.
And memory in variables cfg->sections[curr_section], sect->entries[curr_entry] maybe not equal NULL. We must decrement counters curr_section, curr_entry when failed to realloc.

Fixes eaafbad419bf ("cfgfile: library to interpret config files")
Acked-by on v1 1/1
#2 lore raw
In reply to Dmitriy Yakovlev
Quoted 13 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Dmitriy Yakovlev
Sent: Tuesday, February 7, 2017 2:51 AM
To: [email protected]
Cc: Dmitriy Yakovlev <[email protected]>
Subject: [dpdk-dev] [PATCH] cfgfile: fix uninitialized variable on load error

Uninitialized scalar variable. Using uninitialized value cfg-

Quoted 1 line

sections[curr_section]->num_entries when calling rte_cfgfile_close.

And memory in variables cfg->sections[curr_section], sect-

Quoted 1 line

entries[curr_entry] maybe not equal NULL. We must decrement counters

Quoted 9 lines

curr_section, curr_entry when failed to realloc.

Fixes eaafbad419bf ("cfgfile: library to interpret config files")
---
 lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
 1 file changed, 4 insertions(+)
#3 lore raw
Quoted 8 lines
Quoted 8 lines

Uninitialized scalar variable. Using uninitialized value cfg-

Quoted 1 line

sections[curr_section]->num_entries when calling rte_cfgfile_close.

And memory in variables cfg->sections[curr_section], sect-

Quoted 1 line

entries[curr_entry] maybe not equal NULL. We must decrement counters

curr_section, curr_entry when failed to realloc.

Fixes eaafbad419bf ("cfgfile: library to interpret config files")
Quoted 7 lines
Quoted 5 lines
---
 lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
 1 file changed, 4 insertions(+)

Applied, thanks