bin/tar incorrectly parse '[^...]' patterns in --exclude

From: Mykola Dzham <i_at_levsha.me>
Date: Tue, 5 Oct 2010 11:27:24 +0300
Hi!
bsd tar parse only '[!...]' as negate pattern, but gnu tar and bsd tar
on 8-STABLE parse '[^...]' too:

# uname -a
FreeBSD laptop.levsha.me 9.0-CURRENT FreeBSD 9.0-CURRENT #4 r212602M: Wed Sep 15 04:50:20 EEST 2010     root_at_laptop.levsha.me:/usr/obj/usr/src/sys/LEVSHA  amd64
# tar --version
bsdtar 2.8.3 - libarchive 2.7.901a
# tar -tzvf test.tbz
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 a
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 b
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 c
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 d
# tar -tzvf test.tbz --exclude '[!a]' 
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 a
# tar -tzvf test.tbz --exclude '[^a]'
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 b
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 c
-rw-r--r--  0 levsha levsha      0 Oct  5 01:27 d
# gtar -tzvf test.tbz --exclude '[^a]'
-rw-r--r-- levsha/levsha     0 2010-10-05 01:27 a
#

# uname -a
FreeBSD levsha.kiev.xxx.com.ua 8.1-STABLE FreeBSD 8.1-STABLE #10 r212252: Mon Sep  6 13:12:07 EEST 2010     root_at_levsha.kiev.xxx.com.ua:/usr/obj/usr/src/sys/LEVSHA  i386
# tar --version
bsdtar 2.7.0 - libarchive 2.7.0
# tar -tzvf test.tbz
-rw-r--r--  0 levsha levsha      0  5 ΦΟΧ 01:27 a
-rw-r--r--  0 levsha levsha      0  5 ΦΟΧ 01:27 b
-rw-r--r--  0 levsha levsha      0  5 ΦΟΧ 01:27 c
-rw-r--r--  0 levsha levsha      0  5 ΦΟΧ 01:27 d
# tar -tzvf test.tbz --exclude '[!a]'
-rw-r--r--  0 levsha levsha      0  5 ΦΟΧ 01:27 a
# tar -tzvf test.tbz --exclude '[^a]'
-rw-r--r--  0 levsha levsha      0  5 ΦΟΧ 01:27 a
# 

Fix:

Index: usr.bin/tar/pathmatch.c
===================================================================
--- usr.bin/tar/pathmatch.c	(revision 212602)
+++ usr.bin/tar/pathmatch.c	(working copy)
_at__at_ -35,7 +35,7 _at__at_
 
 /*
  * Check whether a character 'c' is matched by a list specification [...]:
- *    * Leading '!' negates the class.
+ *    * Leading '!' or '^' negates the class.
  *    * <char>-<char> is a range of characters
  *    * \<char> removes any special meaning for <char>
  *
_at__at_ -60,7 +60,7 _at__at_
 	(void)flags; /* UNUSED */
 
 	/* If this is a negated class, return success for nomatch. */
-	if (*p == '!' && p < end) {
+	if ((*p == '!' || *p == '^') && p < end) {
 		match = 0;
 		nomatch = 1;
 		++p;

-- 
LEFT-(UANIC|RIPE)
JID: levsha_at_jabber.net.ua
PGP fingerprint: 1BCD 7C80 2E04 7282 C944  B0E0 7E67 619E 4E72 9280

Received on Tue Oct 05 2010 - 06:56:03 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:08 UTC