From sa@simon.org.ua  Thu Sep 20 07:28:01 2001
Return-Path: <sa@simon.org.ua>
Received: from lion.com.ua (lion.com.ua [213.133.161.130])
	by hub.freebsd.org (Postfix) with ESMTP id 7E68E37B409
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 20 Sep 2001 07:27:57 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
	by lion.com.ua (8.11.4/8.11.4) with ESMTP id f8KERtF01197
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 20 Sep 2001 17:27:55 +0300 (EEST)
	(envelope-from sa@simon.org.ua)
Message-Id: <20010920172441.V1185-100000@lion.com.ua>
Date: Thu, 20 Sep 2001 17:27:54 +0300 (EEST)
From: Andrey Simonenko <simon@simon.org.ua>
To: <FreeBSD-gnats-submit@freebsd.org>
Subject: Patch for usr.bin/hexdump

>Number:         30685
>Category:       bin
>Synopsis:       Patch for usr.bin/hexdump
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    cjc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 20 07:30:03 PDT 2001
>Closed-Date:    Fri Jul 16 09:01:31 GMT 2004
>Last-Modified:  Fri Jul 16 09:01:31 GMT 2004
>Originator:     Andrey Simonenko
>Release:        FreeBSD 4.4-RC i386
>Organization:
>Environment:

FreeBSD 4.4-RC i386

>Description:

hexdump(8) expects that an argument for -e option is always surrounded by
double quote (" ") marks. And following calls generate core-dumps:

$ hexdump -e "" some-file
$ hexdump -e "\"%c\"" -e " " some-file

hexdump(8) shouldn't generate core-dumps in reaction on -e "" option,
instead it should skip this format string as empty.

Following patch fixes described above problem with hexdump(8).

>How-To-Repeat:

$ hexdump -e "" /COPYRIGHT
$ hexdump -e "\"%c\"" -e " " /COPYRIGHT

I checked original hexdump and patched hexdump with different format
strings in -e option, and didn't find any differences in outputs.

>Fix:

diff -ru /usr/src/usr.bin/hexdump/parse.c hexdump/parse.c
--- /usr/src/usr.bin/hexdump/parse.c	Sat Aug 28 04:02:03 1999
+++ hexdump/parse.c	Thu Sep 20 17:01:09 2001
@@ -413,7 +413,7 @@
 	 * If, rep count is greater than 1, no trailing whitespace
 	 * gets output from the last iteration of the format unit.
 	 */
-	for (fu = fs->nextfu;; fu = fu->nextfu) {
+	for (fu = fs->nextfu; fu != NULL; fu = fu->nextfu) {
 		if (!fu->nextfu && fs->bcnt < blocksize &&
 		    !(fu->flags&F_SETREP) && fu->bcnt)
 			fu->reps += (blocksize - fs->bcnt) / fu->bcnt;
@@ -426,8 +426,6 @@
 			if (p2)
 				pr->nospace = p2;
 		}
-		if (!fu->nextfu)
-			break;
 	}
 #ifdef DEBUG
 	for (fu = fs->nextfu; fu; fu = fu->nextfu) {

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: cjc 
State-Changed-When: Thu Sep 20 12:28:57 PDT 2001 
State-Changed-Why:  
Patch looks good. Doing some checks and will commit if it works out. 


Responsible-Changed-From-To: freebsd-bugs->cjc 
Responsible-Changed-By: cjc 
Responsible-Changed-When: Thu Sep 20 12:28:57 PDT 2001 
Responsible-Changed-Why:  
Made the changes in my local repo and doing tests before commit. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30685 

From: Andrey Simonenko <simon@simon.org.ua>
To: <FreeBSD-gnats-submit@freebsd.org>
Cc:  
Subject: bin/30685: Patch for usr.bin/hexdump
Date: Thu, 20 Sep 2001 17:27:54 +0300 (EEST)

 >Number:         30685
 >Category:       bin
 >Synopsis:       Patch for usr.bin/hexdump
 >Confidential:   no
 >Severity:       non-critical
 >Priority:       low
 >Responsible:    freebsd-bugs
 >State:          open
 >Quarter:        
 >Keywords:       
 >Date-Required:
 >Class:          change-request
 >Submitter-Id:   current-users
 >Arrival-Date:   Thu Sep 20 07:30:03 PDT 2001
 >Closed-Date:
 >Last-Modified:
 >Originator:     Andrey Simonenko
 >Release:        FreeBSD 4.4-RC i386
 >Organization:
 >Environment:
 
 FreeBSD 4.4-RC i386
 
 >Description:
 
 hexdump(8) expects that an argument for -e option is always surrounded by
 double quote (" ") marks. And following calls generate core-dumps:
 
 $ hexdump -e "" some-file
 $ hexdump -e "\"%c\"" -e " " some-file
 
 hexdump(8) shouldn't generate core-dumps in reaction on -e "" option,
 instead it should skip this format string as empty.
 
 Following patch fixes described above problem with hexdump(8).
 
 >How-To-Repeat:
 
 $ hexdump -e "" /COPYRIGHT
 $ hexdump -e "\"%c\"" -e " " /COPYRIGHT
 
 I checked original hexdump and patched hexdump with different format
 strings in -e option, and didn't find any differences in outputs.
 
 >Fix:
 
 diff -ru /usr/src/usr.bin/hexdump/parse.c hexdump/parse.c
 --- /usr/src/usr.bin/hexdump/parse.c	Sat Aug 28 04:02:03 1999
 +++ hexdump/parse.c	Thu Sep 20 17:01:09 2001
 @@ -413,7 +413,7 @@
  	 * If, rep count is greater than 1, no trailing whitespace
  	 * gets output from the last iteration of the format unit.
  	 */
 -	for (fu = fs->nextfu;; fu = fu->nextfu) {
 +	for (fu = fs->nextfu; fu != NULL; fu = fu->nextfu) {
  		if (!fu->nextfu && fs->bcnt < blocksize &&
  		    !(fu->flags&F_SETREP) && fu->bcnt)
  			fu->reps += (blocksize - fs->bcnt) / fu->bcnt;
 @@ -426,8 +426,6 @@
  			if (p2)
  				pr->nospace = p2;
  		}
 -		if (!fu->nextfu)
 -			break;
  	}
  #ifdef DEBUG
  	for (fu = fs->nextfu; fu; fu = fu->nextfu) {
 
 >Release-Note:
 >Audit-Trail:
 >Unformatted:
 
 To Unsubscribe: send mail to majordomo@FreeBSD.org
 with "unsubscribe freebsd-bugs" in the body of the message
State-Changed-From-To: analyzed->closed 
State-Changed-By: johan 
State-Changed-When: Fri Jul 16 08:57:57 GMT 2004 
State-Changed-Why:  
This was fixed in rev 1.10 and MFCed in rev 1.4.2.1 of parse.c. 

Crist, I hope you do not mind me closing this :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30685 
>Unformatted:
