[dpdk-dev] cfgfile: fix unitialised buffer and improve reading from nfs filesystem.

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

Commit Message

Daniel Mrzyglod June 26, 2015, 8:37 a.m. UTC
  Nature of the problem was not initialised buffer[256] on special condition
there were probability that program will work on unitialised data that
could provide unexpected program behaviour.

Adding additional transparent I/O buffer for I/O operations
improve reading on heavyloaded enviroments with NFS.

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

Comments

Bruce Richardson June 26, 2015, 2:05 p.m. UTC | #1
On Fri, Jun 26, 2015 at 10:37:13AM +0200, Daniel Mrzyglod wrote:
> Nature of the problem was not initialised buffer[256] on special condition
> there were probability that program will work on unitialised data that
> could provide unexpected program behaviour.
> 
> Adding additional transparent I/O buffer for I/O operations
> improve reading on heavyloaded enviroments with NFS.
> 
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
>  lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index b81c273..88fcb46 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -93,10 +93,14 @@ rte_cfgfile_load(const char *filename, int flags)
>  	int curr_section = -1;
>  	int curr_entry = -1;
>  	char buffer[256];
> +	char f_streambuff[BUFSIZ];
>  	int lineno = 0;
>  	struct rte_cfgfile *cfg = NULL;
> +	memset(buffer, '\0', 256*sizeof(char));
> +	memset(f_streambuff, '\0', BUFSIZ);

Need a blank line before the memsets.
The 256*sizeof(char) needs whitespace around it - however, it's probably best
just replaced by "sizeof(buffer)". For consistency, the same change could be
made to the f_streambuff memset too.

/Bruce
  
Daniel Mrzyglod June 29, 2015, 2:32 p.m. UTC | #2
I send v2 of this patch. 

I removed in v2 special buffer for file descriptor.
It helped when we haved unitilized buffer[256] because of diferent fgets/fread/fwrite behaviour
when the buffer was set. 

The real and only problem was uninitialized buffer[256] and this workaround IO buffer is not needed for patch.

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Daniel Mrzyglod
> Sent: Friday, June 26, 2015 10:37 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] cfgfile: fix unitialised buffer and improve reading
> from nfs filesystem.
> 
> Nature of the problem was not initialised buffer[256] on special condition
> there were probability that program will work on unitialised data that
> could provide unexpected program behaviour.
> 
> Adding additional transparent I/O buffer for I/O operations
> improve reading on heavyloaded enviroments with NFS.
> 
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
>  lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index b81c273..88fcb46 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -93,10 +93,14 @@ rte_cfgfile_load(const char *filename, int flags)
>  	int curr_section = -1;
>  	int curr_entry = -1;
>  	char buffer[256];
> +	char f_streambuff[BUFSIZ];
>  	int lineno = 0;
>  	struct rte_cfgfile *cfg = NULL;
> +	memset(buffer, '\0', 256*sizeof(char));
> +	memset(f_streambuff, '\0', BUFSIZ);
> 
>  	FILE *f = fopen(filename, "r");
> +	setbuf(f, f_streambuff);
>  	if (f == NULL)
>  		return NULL;
> 
> --
> 2.1.0
  

Patch

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b81c273..88fcb46 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -93,10 +93,14 @@  rte_cfgfile_load(const char *filename, int flags)
 	int curr_section = -1;
 	int curr_entry = -1;
 	char buffer[256];
+	char f_streambuff[BUFSIZ];
 	int lineno = 0;
 	struct rte_cfgfile *cfg = NULL;
+	memset(buffer, '\0', 256*sizeof(char));
+	memset(f_streambuff, '\0', BUFSIZ);
 
 	FILE *f = fopen(filename, "r");
+	setbuf(f, f_streambuff);
 	if (f == NULL)
 		return NULL;