magic(3): Fix program name extraction from core dumps.
authorSascha Wildner <saw@online.de>
Tue, 14 Apr 2009 22:44:25 +0000 (00:44 +0200)
committerSascha Wildner <saw@online.de>
Tue, 14 Apr 2009 22:45:34 +0000 (00:45 +0200)
Remove trailing whitespace only instead of unconditionally removing the
last character from the program name (see comments).

Reported-by: hasso
Located-by: Eric J. Christeson
Taken-from:  FreeBSD's libmagic

contrib/file-4/src/readelf.c

index 3c7472b..1cb65ea 100644 (file)
@@ -689,7 +689,11 @@ core:
                                    &nbuf[doff + prpsoffsets(i)];
                                for (cp = cname; *cp && isprint(*cp); cp++)
                                        continue;
-                               if (cp > cname)
+                               /*
+                                * Linux apparently appends a space at the end
+                                * of the command line: remove it.
+                                */
+                               while (cp > cname && isspace(cp[-1]))
                                        cp--;
                                if (file_printf(ms, ", from '%.*s'",
                                    (int)(cp - cname), cname) == -1)