Subject: bin/7278: `install -B with unexpected argument' causes infinite loop
To: None <gnats-bugs@gnats.netbsd.org>
From: NAKAJIMA Yoshihiro <nakayosh@kcn.ne.jp>
List: netbsd-bugs
Date: 03/30/1999 01:15:49
>Number:         7278
>Category:       bin
>Synopsis:       `install -B with unexpected argument' causes infinite loop
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 29 08:20:01 1999
>Last-Modified:
>Originator:     NAKAJIMA Yoshihiro
>Organization:
>Release:        NetBSD-current 1999/03/28
>Environment:
System: NetBSD asura 1.3K NetBSD 1.3K (ASURA) #3: Mon Mar 29 07:54:15 JST 1999 nakayosh@asura:/usr/src/sys/arch/i386/compile/ASURA i386


>Description:

`install -B with unexpected argument' (such as ``install -B .% foo bar'')
causes infinite loop.

>How-To-Repeat:

mkdir TEST; cd TEST; touch foo bar
install -B .% foo bar

>Fix:

This is my fix.
Or should it be treated as error?

diff -u src/usr.bin/xinstall/xinstall.c.ORIG src/usr.bin/xinstall/xinstall.c
--- src/usr.bin/xinstall/xinstall.c.ORIG	Thu Mar 25 21:21:20 1999
+++ src/usr.bin/xinstall/xinstall.c	Tue Mar 30 00:54:30 1999
@@ -74,6 +74,7 @@
 struct group *gp;
 int dobackup=0, docopy=0, dodir=0, dostrip=0, dolink=0, dopreserve=0,
     dorename = 0;
+static int numberedbackup = 0;
 int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
 char pathbuf[MAXPATHLEN];
 uid_t uid;
@@ -117,6 +118,18 @@
 		switch((char)ch) {
 		case 'B':
 			suffix = optarg;
+			numberedbackup = 0;
+			{
+				char suffix_expanded0[FILENAME_MAX],
+				     suffix_expanded1[FILENAME_MAX];
+				(void)snprintf(suffix_expanded0, FILENAME_MAX,
+					       suffix, 0);
+				(void)snprintf(suffix_expanded1, FILENAME_MAX,
+					       suffix, 1);
+				if (strcmp(suffix_expanded0, suffix_expanded1)
+				    != 0)
+					numberedbackup = 1;
+			}
 			/* fall through; -B implies -b */
 		case 'b':
 			dobackup = 1;
@@ -570,7 +583,7 @@
 {
 	char backup[FILENAME_MAX];
 	
-	if (strchr(suffix, '%')) {
+	if (numberedbackup) {
 		/* Do numbered backup */
 		int cnt;
 		char suffix_expanded[FILENAME_MAX];

>Audit-Trail:
>Unformatted: