Skip to contentSkip to conversation

rpc.idmapd: Sections in idmapd.conf are ignored.

PATCH In review Steve Dickson 2 participants 4 messages Nov 14, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rpc.idmapd: Sections in idmapd.conf are ignored.

In the parsing routine, conf_parse_line(), a string is not being null terminated which is causing section of the config file to be ignored.

https://bugzilla.linux-nfs.org/show_bug.cgi?id=205

---
 support/nfs/conffile.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
support/nfs/conffile.c +2 -1
index fa0dc6b..3990578 100644
@@ -256,13 +256,14 @@ conf_parse_line(int trans, char *line, size_t sz)
 			val++, j++;
 		if (*val)
 			i = j;
-		section = malloc(i);
+		section = malloc(i+1);
 		if (!section) {
 			xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln,
 						(unsigned long)i);
 			return;
 		}
 		strncpy(section, line, i);
+		section[i] = '\0';
 
 		if (arg) 
 			free(arg);
Signature · 1 line
1.7.7
#1 lore raw

Steve Dickson wrote:

In the parsing routine, conf_parse_line(), a string is not being null terminated which is causing section of the config file to be ignored.

https://bugzilla.linux-nfs.org/show_bug.cgi?id=205

---

   support/nfs/conffile.c |    3 ++-
   1 files changed, 2 insertions(+), 1 deletions(-)
  diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
  index fa0dc6b..3990578 100644
  --- a/support/nfs/conffile.c
  +++ b/support/nfs/conffile.c
  @@ -256,13 +256,14 @@ conf_parse_line(int trans, char *line, size_t sz)
   			val++, j++;
   		if (*val)
   			i = j;
  -		section = malloc(i);
  +		section = malloc(i+1);
   		if (!section) {
   			xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln,
   						(unsigned long)i);
   			return;
   		}
   		strncpy(section, line, i);
  +		section[i] = '\0';
   		if (arg) 
   			free(arg);

Use of strdup() would not only make the code simpler but would eliminate the possibility of introducing this kind of bug.

#2 lore raw
Quoted 31 lines · Jim Rees

Steve Dickson wrote:

In the parsing routine, conf_parse_line(), a string is not being null terminated which is causing section of the config file to be ignored.

https://bugzilla.linux-nfs.org/show_bug.cgi?id=205

---

   support/nfs/conffile.c |    3 ++-
   1 files changed, 2 insertions(+), 1 deletions(-)
  diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
  index fa0dc6b..3990578 100644
  --- a/support/nfs/conffile.c
  +++ b/support/nfs/conffile.c
  @@ -256,13 +256,14 @@ conf_parse_line(int trans, char *line, size_t sz)
   			val++, j++;
   		if (*val)
   			i = j;
  -		section = malloc(i);
  +		section = malloc(i+1);
   		if (!section) {
   			xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln,
   						(unsigned long)i);
   			return;
   		}
   		strncpy(section, line, i);
  +		section[i] = '\0';
Quoted 5 lines
   		if (arg) 
   			free(arg);

Use of strdup() would not only make the code simpler but would eliminate the possibility of introducing this kind of bug.

I thought of that... but from my reading of the code the entire string is not wanted, just a section of the string is needed...

thanks!

steved.

#3 lore raw
In reply to Steve Dickson
Quoted 7 lines · Steve Dickson

In the parsing routine, conf_parse_line(), a string is not being null terminated which is causing section of the config file to be ignored.

https://bugzilla.linux-nfs.org/show_bug.cgi?id=205

Committed...

steved.

Quoted 24 lines
---
 support/nfs/conffile.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
support/nfs/conffile.c +2 -1
index fa0dc6b..3990578 100644
@@ -256,13 +256,14 @@ conf_parse_line(int trans, char *line, size_t sz)
 			val++, j++;
 		if (*val)
 			i = j;
-		section = malloc(i);
+		section = malloc(i+1);
 		if (!section) {
 			xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln,
 						(unsigned long)i);
 			return;
 		}
 		strncpy(section, line, i);
+		section[i] = '\0';
 
 		if (arg) 
 			free(arg);