[dpdk-dev,v2] cfgfile: fix unitialised buffer

Message ID 1435587625-5096-1-git-send-email-danielx.t.mrzyglod@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Daniel Mrzyglod June 29, 2015, 2:20 p.m. UTC
  Nature of the problem was not initialised buffer[256], there were probability
that operation system will provide previously used memory and on special condition
there were probability that string operations will work on random data that
could provide unexpected program behaviour.

Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
 lib/librte_cfgfile/rte_cfgfile.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Bruce Richardson June 29, 2015, 2:33 p.m. UTC | #1
On Mon, Jun 29, 2015 at 04:20:25PM +0200, Daniel Mrzyglod wrote:
> Nature of the problem was not initialised buffer[256], there were probability
> that operation system will provide previously used memory and on special condition
> there were probability that string operations will work on random data that
> could provide unexpected program behaviour.
> 
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
>  lib/librte_cfgfile/rte_cfgfile.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index b81c273..9c85e9f 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -96,7 +96,10 @@ rte_cfgfile_load(const char *filename, int flags)
>  	int lineno = 0;
>  	struct rte_cfgfile *cfg = NULL;
>  
> +	memset(buffer, '\0', sizeof(buffer));
> +
>  	FILE *f = fopen(filename, "r");
> +
>  	if (f == NULL)
>  		return NULL;
>  
> -- 
> 2.1.0
> 
How about just adding "= {0}" to the end of the definition of buffer?

/Bruce
  

Patch

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b81c273..9c85e9f 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -96,7 +96,10 @@  rte_cfgfile_load(const char *filename, int flags)
 	int lineno = 0;
 	struct rte_cfgfile *cfg = NULL;
 
+	memset(buffer, '\0', sizeof(buffer));
+
 	FILE *f = fopen(filename, "r");
+
 	if (f == NULL)
 		return NULL;