Skip to contentSkip to conversation

Rergession in readcmd (commit 55c46b7)

DISCUSSION Alexey Gladkov 2 participants 4 messages Aug 26, 2009 – Nov 26, 2009

lore
Share & tools
lore
#0 lore raw

Greeting!

readcmd put trash in the variables.

Test case:

$ cat /tmp/conf
Include common.conf
FullSpeedCPU yes
$ cat /tmp/z.sh
while read option params; do
  printf '[%s] [%s]\n' "$option" "$params"
done < /tmp/conf

Result:

$ dash /tmp/z.sh
[Include] [common.conf]
[FullSpeedCPU] [yesFnf]
Signature · 1 line
Rgrds, legion
#1 lore raw
Quoted 15 lines · Alexey Gladkov

Greeting!

readcmd put trash in the variables.

Test case:

$ cat /tmp/conf
Include common.conf
FullSpeedCPU yes
$ cat /tmp/z.sh
while read option params; do
 printf '[%s] [%s]\n' "$option" "$params"
done < /tmp/conf
Quoted 5 lines

Result:

$ dash /tmp/z.sh
[Include] [common.conf]
[FullSpeedCPU] [yesFnf]

Thanks for the report. It's an off-by-one error causing the NUL termination to disappear.

ChangeLog +4 -0
index 9d397e4..13c9010 100644
@@ -1,3 +1,7 @@
+2009-08-31  Herbert Xu <[email protected]>
+
+	* Fix NUL termination in readcmd.
+
 2009-08-11  Herbert Xu <[email protected]>
 
 	* Pass EV_TESTED into evalcmd.
src/miscbltin.c +1 -1
index cca0f6c..be746b2 100644
@@ -182,7 +182,7 @@ resetbs:
 		backslash = 0;
 	}
 	STACKSTRNUL(p);
-	readcmd_handle_line(stackblock(), ap, p - (char *)stackblock());
+	readcmd_handle_line(stackblock(), ap, p + 1 - (char *)stackblock());
 	return status;
 }
 

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
Quoted 6 lines · Herbert Xu
Quoted 3 lines
$ dash /tmp/z.sh
[Include] [common.conf]
[FullSpeedCPU] [yesFnf]

Thanks for the report. It's an off-by-one error causing the NUL termination to disappear.

I found another example:

$ tr -d '[:print:]' < /etc/passwd |tr -d '\t\n' |wc -c
0
$ dash -c 'while read o p; do printf "[%s] [%s]\n" "$o" "$p"; done <
/etc/passwd' |tr -d '[:print:]' |tr -d '[:space:]' |wc -c
61

bug is not fixed yet :(

Signature · 1 line
Rgrds, legion
#3 lore raw
Quoted 11 lines · Alexey Gladkov

I found another example:

$ tr -d '[:print:]' < /etc/passwd |tr -d '\t\n' |wc -c
0
$ dash -c 'while read o p; do printf "[%s] [%s]\n" "$o" "$p"; done <
/etc/passwd' |tr -d '[:print:]' |tr -d '[:space:]' |wc -c
61

bug is not fixed yet :(

This bug is caused by an off-by-one error in the recordregion call in readcmd. It included the terminating NUL in the region which causes ifsbreakup to include the string after it for scanning.

Setting the correct length fixes the problem.

ChangeLog +4 -0
index fabb0e1..7be8e86 100644
@@ -1,3 +1,7 @@
+2009-11-26  Herbert Xu <[email protected]>
+
+	Fix off-by-one recordregion in readcmd.
+
 2009-09-28  Jim Meyering  <[email protected]>
 
 	don't read-uninitialized for \177 in a here-doc
src/miscbltin.c +1 -1
index ec9872d..046f2f2 100644
@@ -84,7 +84,7 @@ readcmd_handle_line(char *line, char **ap, size_t len)
 	backup = sstrdup(line);
 
 	arglist.lastp = &arglist.list;
-	recordregion(0, len, 0);
+	recordregion(0, len - 1, 0);
 	
 	ifsbreakup(s, &arglist);
 	*arglist.lastp = NULL;

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt