From andreas@infosys.heitec.net  Sat Feb 13 19:55:03 1999
Received: from urmel.infosys.heitec.net ([195.63.14.1])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA13954
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 13 Feb 1999 19:55:00 -0800 (PST)
          (envelope-from andreas@infosys.heitec.net)
Received: (from smtpd@localhost)
	by urmel.infosys.heitec.net (8.8.5/8.8.5) id EAA09798;
	Sun, 14 Feb 1999 04:52:50 +0100
Received: from troubadix.infosys.heitec.net(193.101.232.22)
 via SMTP by urmel.infosys.heitec.net, id smtpda09796; Sun Feb 14 04:52:45 1999
Received: (from andreas@localhost)
	by troubadix.infosys.heitec.net (8.8.7/8.8.5) id EAA12489;
	Sun, 14 Feb 1999 04:55:02 +0100 (MET)
Received: from weiden.infosys.heitec.net (weiden.infosys.heitec.net [193.101.232.43])
	by majestix.infosys.heitec.net (8.8.7/8.8.5) with ESMTP id EAA23099
	for <andreas@majestix.infosys.heitec.net>; Sun, 14 Feb 1999 04:50:00 +0100 (MET)
Received: (from root@localhost)
	by weiden.infosys.heitec.net (8.9.2/8.9.1) id EAA33722;
	Sun, 14 Feb 1999 04:48:23 +0100 (CET)
	(envelope-from andreas)
Message-Id: <199902140348.EAA33722@weiden.infosys.heitec.net>
Date: Sun, 14 Feb 1999 04:48:23 +0100 (CET)
From: andreas@infosys.heitec.net
Sender: andreas@infosys.heitec.net
Reply-To: andreas@infosys.heitec.net
To: FreeBSD-gnats-submit@freebsd.org
Cc: gnats@openbsd.org
Subject: chflags does strange things
X-Send-Pr-Version: 3.2

>Number:         10071
>Category:       bin
>Synopsis:       flags given to chflags depend on sequence
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 13 20:00:00 PST 1999
>Closed-Date:    Fri May 21 10:04:28 PDT 1999
>Last-Modified:  Fri May 21 10:05:04 PDT 1999
>Originator:     Andreas Klussmann
>Release:        FreeBSD 4.0-CURRENT i386 (ctm 5068)
>Organization:
HEITEC Informationssysteme GmbH; Naegelsbachstrasse 26; 91052 Erlangen
>Environment:

	FreeBSD, OpenBSD; perhaps NetBSD
	kern_securelevel_enable set to NO

>Description:

chflags clears all flags supplied on the command line after a clearing flag like dump(!) or noschg, etc.
The error is in /usr/src/bin/ls/stat_flags.c in a loop scanning the arguments. The variable 'clear', which
is used as flag for the prepended 'no' string, is only initialised before the loop begins intead of beeing
reset on every iteration.

>How-To-Repeat:

	# touch /tmp/flags
	# chflags schg,uchg /tmp/flags
	# ls -lo /tmp/flags
	-rwx------  1 root  wheel  uchg,schg 0 Feb 14 04:29 /tmp/flags
	# chflags dump,schg,uchg /tmp/flags
	# ls -lo /tmp/flags
	-rwx------  1 root  wheel  - 0 Feb 14 04:29 /tmp/flags
	# chflags noschg,dump,uchg /tmp/flags
	# ls -lo /tmp/flags
	-rwx------  1 root  wheel  uchg,nodump 0 Feb 14 04:29 /tmp/flags


>Fix:
	
# cd /usr/src/bin/ls
# cvs diff -u
cvs diff: Diffing .
Index: stat_flags.c
===================================================================
RCS file: /home/cvs/src/bin/ls/stat_flags.c,v
retrieving revision 1.9
diff -u -r1.9 stat_flags.c
--- stat_flags.c	1998/01/09 06:14:59	1.9
+++ stat_flags.c	1999/02/14 03:16:31
@@ -118,13 +118,13 @@
 	int clear;
 	char *string, *p;
 
-	clear = 0;
 	if (setp)
 		*setp = 0;
 	if (clrp)
 		*clrp = 0;
 	string = *stringp;
 	while ((p = strsep(&string, "\t ,")) != NULL) {
+		clear = 0;
 		*stringp = p;
 		if (*p == '\0')
 			continue;



>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jmz 
State-Changed-When: Fri May 21 10:04:28 PDT 1999 
State-Changed-Why:  
Patch applied. Thanks! 
>Unformatted:
