Re: is our printf(1) behavior correct w.r.t \0 escapes?
On 28-Jan-2003 John Reynolds~ wrote: We need to echo a string *and* a NUL character (\0) into a stream so that a program that delimits its input by \0 characters will do the right thing. He had been doing this via printf(1) like so: % printf some string\0 | some_process however, it never worked under FreeBSD. Upon further inspection, our printf(1) does not work like the GNU one with the above string. Consider this from a linux box: linux [~]374% printf foo\0bar\0 | od -c 000 f o o \0 b a r \0 010 Now the same command from a FreeBSD (4.7-STABLE) box: freebsd [~]76% printf foo\0bar\0 | od -c 000f o o 003 Works fine under -current: $ printf foo\0bar\0 | od -c 000f o o \0 b a r \0 After checking the man pages, I also used a complete octal constant but that doesn't work either: linux [~]376% printf foo\ | od -c 000 f o o \0 004 freebsd [~]77% printf foo\ | od -c 000f o o 003 This also works under -current: $ printf foo\ | od -c 000f o o \0 004 I checked our implementation and it seems wrong. The first step done in the source code is to interpolate all escape sequences. However, when it does this and the octal number happens to be 0, this fact is not captured later on and that 0 becomes the NULL terminator for the string and nothing else is printed after it. linux [~]379% printf foo\0%d 4 | od -c 000 f o o \0 4 005 freebsd [~]78% printf foo\0%d 4 | od -c printf: missing format character 000f o o 003 This also works under -current: $ printf foo\0%d 4 | od -c 000f o o \0 4 005 This behavior has been checked on HP-UX and Solaris and those two systems are identical to the Linux one. It seems to me that our printf(1)'s behavior is incorrect. Comments? It may very well be that printf (or libc?) has a bug under -stable. Are you using any unusual optimization settings in /etc/make.conf, by the way? When did you last upgrade? -- Conrad Sabatier [EMAIL PROTECTED] - In Unix veritas To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: is our printf(1) behavior correct w.r.t \0 escapes?
[ On Tuesday, January 28, Conrad Sabatier wrote: ] Works fine under -current: $ printf foo\0bar\0 | od -c 000f o o \0 b a r \0 This also works under -current: $ printf foo\ | od -c 000f o o \0 004 This also works under -current: $ printf foo\0%d 4 | od -c 000f o o \0 4 005 That's good that all of those work under -current. It may very well be that printf (or libc?) has a bug under -stable. Are you using any unusual optimization settings in /etc/make.conf, by the way? When did you last upgrade? nope, nothing unusual. CFLAGS= -O -pipe The last time I updated and installed world/kernel was Dec 26th of 2002 (4.7-STABLE). Maybe if it's not a libc problem but just a printf(1) src problem we could get an MFC done ... Thanks for the info. At least we know that -current acts like other OS's. -Jr -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |John Reynolds Sr. Component Design Engineer - ICG/EID/Si Engineering | |Intel Corporation MS: CH6-302 Phone: 480-554-9092 pgr: 602-868-6512 | |[EMAIL PROTECTED] http://www-aec.ch.intel.com/~jreynold/ | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: is our printf(1) behavior correct w.r.t \0 escapes?
On 28-Jan-2003 John Reynolds~ wrote: [ On Tuesday, January 28, Conrad Sabatier wrote: ] It may very well be that printf (or libc?) has a bug under -stable. Are you using any unusual optimization settings in /etc/make.conf, by the way? When did you last upgrade? nope, nothing unusual. CFLAGS= -O -pipe The last time I updated and installed world/kernel was Dec 26th of 2002 (4.7-STABLE). Maybe if it's not a libc problem but just a printf(1) src problem we could get an MFC done ... Unless it's already been done. :-) Can you check the RCS Id in /usr/src/usr.bin/printf/printf.c? Here's what I have: $FreeBSD: src/usr.bin/printf/printf.c,v 1.26 2002/09/04 23:29:05 dwmalone Exp $ Thanks for the info. At least we know that -current acts like other OS's. Now, if we have identical versions, we have a bona fide mystery on our hands here. :-) -- Conrad Sabatier [EMAIL PROTECTED] - In Unix veritas To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: is our printf(1) behavior correct w.r.t \0 escapes?
[ On Tuesday, January 28, Conrad Sabatier wrote: ] Unless it's already been done. :-) Can you check the RCS Id in /usr/src/usr.bin/printf/printf.c? Here's what I have: $FreeBSD: src/usr.bin/printf/printf.c,v 1.26 2002/09/04 23:29:05 dwmalone Exp $ Now, if we have identical versions, we have a bona fide mystery on our hands here. :-) Well, this is what I have: $FreeBSD: src/usr.bin/printf/printf.c,v 1.12.6.6 2002/04/29 16:45:16 jmallett according to the CVS repo, 1.26 has RELENG_5_0* tags as well as HEAD while the latest on the RELENG_4 branch is still what I have--1.12.6.6. -Jr -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |John Reynolds Sr. Component Design Engineer - ICG/EID/Si Engineering | |Intel Corporation MS: CH6-302 Phone: 480-554-9092 pgr: 602-868-6512 | |[EMAIL PROTECTED] http://www-aec.ch.intel.com/~jreynold/ | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: is our printf(1) behavior correct w.r.t \0 escapes?
On 28-Jan-2003 John Reynolds~ wrote: [ On Tuesday, January 28, Conrad Sabatier wrote: ] Unless it's already been done. :-) Can you check the RCS Id in /usr/src/usr.bin/printf/printf.c? Here's what I have: $FreeBSD: src/usr.bin/printf/printf.c,v 1.26 2002/09/04 23:29:05 dwmalone Exp $ Now, if we have identical versions, we have a bona fide mystery on our hands here. :-) Well, this is what I have: $FreeBSD: src/usr.bin/printf/printf.c,v 1.12.6.6 2002/04/29 16:45:16 jmallett according to the CVS repo, 1.26 has RELENG_5_0* tags as well as HEAD while the latest on the RELENG_4 branch is still what I have--1.12.6.6. Ah, OK. So there *is* a difference. I can't imagine there being anything unsafe about using the 5.0 version under -stable. But it would be best to confirm this. Perhaps you should file a PR? -- Conrad Sabatier [EMAIL PROTECTED] - In Unix veritas To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: is our printf(1) behavior correct w.r.t \0 escapes?
[ On Tuesday, January 28, Conrad Sabatier wrote: ] Ah, OK. So there *is* a difference. I can't imagine there being anything unsafe about using the 5.0 version under -stable. But it would be best to confirm this. Perhaps you should file a PR? I will pull the -current sources tonight, compile under a fresh -STABLE and if things work and don't appear broken in any manner I will file a PR. Thanks for your help. -Jr -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |John Reynolds Sr. Component Design Engineer - ICG/EID/Si Engineering | |Intel Corporation MS: CH6-302 Phone: 480-554-9092 pgr: 602-868-6512 | |[EMAIL PROTECTED] http://www-aec.ch.intel.com/~jreynold/ | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message