From 15524157755d0d1452624d1e66659dba2bf6a7c3 Mon Sep 17 00:00:00 2001 From: tjg Date: Thu, 25 Jul 2002 12:19:17 +0000 Subject: Bug: fix globbing of broken symlinks. --- ChangeLog | 4 ++++ configure.ac | 2 +- glob.c | 6 +++--- trip.rc | 8 ++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 436a842..506ff32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -788,3 +788,7 @@ Changes since rc-1.5b2 2002-06-18 Release: rc-1.7. + +2002-07-25 + + Bug: fix globbing of broken symlinks. diff --git a/configure.ac b/configure.ac index ffe9357..6dddecc 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_TYPE_SIZE_T AC_TYPE_UID_T AC_CHECK_TYPE(ssize_t, long) -AC_CHECK_FUNCS(getgroups setpgrp setrlimit) +AC_CHECK_FUNCS(getgroups lstat setpgrp setrlimit) RC_FUNC_GETGROUPS RC_FUNC_SIGSETJMP diff --git a/glob.c b/glob.c index ac26203..b472af9 100644 --- a/glob.c +++ b/glob.c @@ -1,7 +1,7 @@ /* glob.c: rc's (ugly) globber. This code is not elegant, but it works */ #include "rc.h" -#include +#include "stat.h" /* Lifted from autoconf documentation.*/ #if HAVE_DIRENT_H @@ -86,7 +86,7 @@ extern List *glob(List *s) { /* Matches a pattern p against the contents of directory d */ static List *dmatch(char *d, char *p, char *m) { - bool matched = FALSE; + bool matched; List *top, *r; static DIR *dirp; static struct dirent *dp; @@ -107,7 +107,7 @@ static List *dmatch(char *d, char *p, char *m) { if (matched) { char *path = nprint("%s/%s", d, p); - if (stat(path, &s) < 0) + if (lstat(path, &s) < 0) return NULL; r = nnew(List); r->w = ncpy(p); diff --git a/trip.rc b/trip.rc index 8eb4c09..9b4dd13 100644 --- a/trip.rc +++ b/trip.rc @@ -587,6 +587,14 @@ fn x {echo x.y $(x.y)} ~ ``''{whatis -f x} 'fn x {echo x.y $''x.y''} ' || fail sneaky parens bug +# before rc-1.7.1, certain glob patterns could fail on broken symlinks +mkdir $tmp.qux +ln -s /frobnatz $tmp.qux/foo +x=$tmp.qux/foo* +~ $x $tmp.qux/foo || { rm -rf $tmp.qux; fail broken symlink globbing } +x=$tmp.qux*/foo +~ $x $tmp.qux/foo || { rm -rf $tmp.qux; fail broken symlink globbing } + # large file support # this is, by no means, an exhaustive test. since particular file -- cgit v1.2.3