basename bug [patch attached]

Kyle Butt kylebutt at gmail.com
Thu Sep 22 13:58:27 PDT 2005


I found a bug in basename (discovered via pkgsrc) and I've
attached a patch to fix it. Hopefully this helps.

Kyle.
Index: basename.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/basename/basename.c,v
retrieving revision 1.5
diff -u -u -r1.5 basename.c
--- basename.c	18 Sep 2005 10:12:55 -0000	1.5
+++ basename.c	22 Sep 2005 20:23:25 -0000
@@ -59,8 +59,8 @@
 
 	setlocale(LC_ALL, "");
 	
-	suffix = 0;
-	suffixlen = NULL;
+	suffix = NULL;
+	suffixlen = 0;
 
 	while ((ch = getopt(argc, argv, "")) != -1)
 		switch(ch) {
@@ -80,6 +80,10 @@
 	}
 	if ((p = basename(argv[0])) == NULL)
 		err(1, "%s", argv[0]);
+	if (argc == 2) {
+		suffix = argv[1];
+		suffixlen = strlen(argv[1]);
+	}
 	stripsuffix(p, suffix, suffixlen);
 	(void)printf("%s\n", p);
 	exit(0);




More information about the Submit mailing list