Module Name:    src
Committed By:   perry
Date:           Tue Apr  7 19:52:35 UTC 2009

Modified Files:
        src/bin/pax: extern.h file_subs.c options.c pat_rep.c pax.h

Log Message:
Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/bin/pax/extern.h
cvs rdiff -u -r1.61 -r1.62 src/bin/pax/file_subs.c
cvs rdiff -u -r1.103 -r1.104 src/bin/pax/options.c
cvs rdiff -u -r1.28 -r1.29 src/bin/pax/pat_rep.c
cvs rdiff -u -r1.29 -r1.30 src/bin/pax/pax.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/pax/extern.h
diff -u src/bin/pax/extern.h:1.55 src/bin/pax/extern.h:1.56
--- src/bin/pax/extern.h:1.55	Sun Feb 24 20:42:46 2008
+++ src/bin/pax/extern.h	Tue Apr  7 19:52:35 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.55 2008/02/24 20:42:46 joerg Exp $	*/
+/*	$NetBSD: extern.h,v 1.56 2009/04/07 19:52:35 perry Exp $	*/
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -216,7 +216,7 @@
  * pat_rep.c
  */
 int rep_add(char *);
-int pat_add(char *, char *);
+int pat_add(char *, char *, int);
 void pat_chk(void);
 int pat_sel(ARCHD *);
 int pat_match(ARCHD *);

Index: src/bin/pax/file_subs.c
diff -u src/bin/pax/file_subs.c:1.61 src/bin/pax/file_subs.c:1.62
--- src/bin/pax/file_subs.c:1.61	Thu Jan 10 04:24:51 2008
+++ src/bin/pax/file_subs.c	Tue Apr  7 19:52:35 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: file_subs.c,v 1.61 2008/01/10 04:24:51 tls Exp $	*/
+/*	$NetBSD: file_subs.c,v 1.62 2009/04/07 19:52:35 perry Exp $	*/
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)file_subs.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: file_subs.c,v 1.61 2008/01/10 04:24:51 tls Exp $");
+__RCSID("$NetBSD: file_subs.c,v 1.62 2009/04/07 19:52:35 perry Exp $");
 #endif
 #endif /* not lint */
 
@@ -275,15 +275,9 @@
 
 	/*
 	 * We may be running as root, so we have to be sure that link target
-	 * is not a directory, so we lstat and check
+	 * is not a directory, so we lstat and check. XXX: This is still racy.
 	 */
-	if (lstat(arcn->ln_name, &sb) < 0) {
-		syswarn(1, errno, "Cannot link to %s from %s", arcn->ln_name,
-		    arcn->name);
-		return -1;
-	}
-
-	if (S_ISDIR(sb.st_mode)) {
+	if (lstat(arcn->ln_name, &sb) != -1 && S_ISDIR(sb.st_mode)) {
 		tty_warn(1, "A hard link to the directory %s is not allowed",
 		    arcn->ln_name);
 		return -1;

Index: src/bin/pax/options.c
diff -u src/bin/pax/options.c:1.103 src/bin/pax/options.c:1.104
--- src/bin/pax/options.c:1.103	Sat Feb 14 08:10:06 2009
+++ src/bin/pax/options.c	Tue Apr  7 19:52:35 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: options.c,v 1.103 2009/02/14 08:10:06 lukem Exp $	*/
+/*	$NetBSD: options.c,v 1.104 2009/04/07 19:52:35 perry Exp $	*/
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)options.c	8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: options.c,v 1.103 2009/02/14 08:10:06 lukem Exp $");
+__RCSID("$NetBSD: options.c,v 1.104 2009/04/07 19:52:35 perry Exp $");
 #endif
 #endif /* not lint */
 
@@ -692,7 +692,7 @@
 	case LIST:
 	case EXTRACT:
 		for (; optind < argc; optind++)
-			if (pat_add(argv[optind], NULL) < 0)
+			if (pat_add(argv[optind], NULL, NOGLOB_MTCH) < 0)
 				pax_usage();
 		break;
 	case COPY:
@@ -1234,7 +1234,7 @@
 							free(str);
 							continue;
 						}
-						if (pat_add(str, dir) < 0)
+						if (pat_add(str, dir, NOGLOB_MTCH) < 0)
 							tar_usage();
 						sawpat = 1;
 					}
@@ -1254,7 +1254,7 @@
  						break;
 					chdname = *argv++;
 					havechd++;
-				} else if (pat_add(*argv++, chdname) < 0)
+				} else if (pat_add(*argv++, chdname, 0) < 0)
 					tar_usage();
 				else
 					sawpat = 1;
@@ -1642,7 +1642,7 @@
 				cpio_usage();
 			}
 			while ((str = getline(fp)) != NULL) {
-				pat_add(str, NULL);
+				pat_add(str, NULL, 0);
 			}
 			fclose(fp);
 			if (getline_error) {
@@ -1781,7 +1781,7 @@
 	case LIST:
 	case EXTRACT:
 		for (; optind < argc; optind++)
-			if (pat_add(argv[optind], 0) < 0)
+			if (pat_add(argv[optind], NULL, 0) < 0)
 				cpio_usage();
 		break;
 	case COPY:

Index: src/bin/pax/pat_rep.c
diff -u src/bin/pax/pat_rep.c:1.28 src/bin/pax/pat_rep.c:1.29
--- src/bin/pax/pat_rep.c:1.28	Sun Feb 24 20:42:46 2008
+++ src/bin/pax/pat_rep.c	Tue Apr  7 19:52:35 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pat_rep.c,v 1.28 2008/02/24 20:42:46 joerg Exp $	*/
+/*	$NetBSD: pat_rep.c,v 1.29 2009/04/07 19:52:35 perry Exp $	*/
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)pat_rep.c	8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: pat_rep.c,v 1.28 2008/02/24 20:42:46 joerg Exp $");
+__RCSID("$NetBSD: pat_rep.c,v 1.29 2009/04/07 19:52:35 perry Exp $");
 #endif
 #endif /* not lint */
 
@@ -75,7 +75,7 @@
 static int rep_name(char *, size_t, int *, int);
 static int tty_rename(ARCHD *);
 static int fix_path(char *, int *, char *, int);
-static int fn_match(char *, char *, char **);
+static int fn_match(char *, char *, char **, int);
 static char * range_match(char *, int);
 static int checkdotdot(const char *);
 static int resub(regex_t *, regmatch_t *, char *, char *, char *, char *);
@@ -236,7 +236,7 @@
  */
 
 int
-pat_add(char *str, char *chdn)
+pat_add(char *str, char *chdn, int flags)
 {
 	PATTERN *pt;
 
@@ -262,7 +262,7 @@
 	pt->pend = NULL;
 	pt->plen = strlen(str);
 	pt->fow = NULL;
-	pt->flgs = 0;
+	pt->flgs = flags;
 	pt->chdname = chdn;
 	if (pathead == NULL) {
 		pattail = pathead = pt;
@@ -471,7 +471,8 @@
 			if ((arcn->name[pt->plen] == '/') &&
 			    (strncmp(pt->pstr, arcn->name, pt->plen) == 0))
 				break;
-		} else if (fn_match(pt->pstr, arcn->name, &pt->pend) == 0)
+		} else if (fn_match(pt->pstr, arcn->name, &pt->pend,
+		    pt->flgs & NOGLOB_MTCH) == 0)
 			break;
 		pt = pt->fow;
 	}
@@ -509,7 +510,7 @@
  */
 
 static int
-fn_match(char *pattern, char *string, char **pend)
+fn_match(char *pattern, char *string, char **pend, int noglob)
 {
 	char c;
 	char test;
@@ -537,10 +538,14 @@
 			*pend = string;
 			return 0;
 		case '?':
+			if (noglob)
+				goto regular;
 			if ((test = *string++) == '\0')
 				return (-1);
 			break;
 		case '*':
+			if (noglob)
+				goto regular;
 			c = *pattern;
 			/*
 			 * Collapse multiple *'s.
@@ -558,12 +563,14 @@
 			 * General case, use recursion.
 			 */
 			while ((test = *string) != '\0') {
-				if (!fn_match(pattern, string, pend))
+				if (!fn_match(pattern, string, pend, noglob))
 					return (0);
 				++string;
 			}
 			return (-1);
 		case '[':
+			if (noglob)
+				goto regular;
 			/*
 			 * range match
 			 */
@@ -573,6 +580,7 @@
 			break;
 		case '\\':
 		default:
+		regular:
 			if (c != *string++)
 				return (-1);
 			break;

Index: src/bin/pax/pax.h
diff -u src/bin/pax/pax.h:1.29 src/bin/pax/pax.h:1.30
--- src/bin/pax/pax.h:1.29	Sat Feb 14 08:10:06 2009
+++ src/bin/pax/pax.h	Tue Apr  7 19:52:35 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pax.h,v 1.29 2009/02/14 08:10:06 lukem Exp $	*/
+/*	$NetBSD: pax.h,v 1.30 2009/04/07 19:52:35 perry Exp $	*/
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -89,6 +89,7 @@
 	int		flgs;		/* processing/state flags */
 #define MTCH		0x1		/* pattern has been matched */
 #define DIR_MTCH	0x2		/* pattern matched a directory */
+#define NOGLOB_MTCH	0x4		/* non-globbing match */
 	struct pattern	*fow;		/* next pattern */
 } PATTERN;
 

Reply via email to