]> granicus.if.org Git - file/commitdiff
PR/32: Chai T. Rex: Handle file -s <(echo '#!/bin/sh\n') on bash/linux
authorChristos Zoulas <christos@zoulas.com>
Tue, 2 Oct 2018 00:38:33 +0000 (00:38 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 2 Oct 2018 00:38:33 +0000 (00:38 +0000)
src/fsmagic.c

index 7804570534ff24aede7c3c470620ff9c9e0cc1f5..3d7425570b32c135316864bd4a1d9952cfcf4da4 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.78 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.79 2018/10/02 00:38:33 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -308,6 +308,15 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
                buf[nch] = '\0';        /* readlink(2) does not do this */
 
                /* If broken symlink, say so and quit early. */
+#ifdef __linux__
+               /*
+                * linux procfs/devfs makes symlinks like pipe:[3515864880]
+                * that we can't stat their readlink output, so stat the
+                * original filename instead.
+                */
+               if (stat(fn, &tstatbuf) < 0)
+                       return bad_link(ms, errno, buf);
+#else
                if (*buf == '/') {
                        if (stat(buf, &tstatbuf) < 0)
                                return bad_link(ms, errno, buf);
@@ -345,6 +354,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
                        if (stat(tmp, &tstatbuf) < 0)
                                return bad_link(ms, errno, buf);
                }
+#endif
 
                /* Otherwise, handle it. */
                if ((ms->flags & MAGIC_SYMLINK) != 0) {