From sec@42.org  Mon Aug 26 10:27:02 2013
Return-Path: <sec@42.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 45ACB8DF
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Aug 2013 10:27:02 +0000 (UTC)
	(envelope-from sec@42.org)
Received: from ice.42.org (ice.42.org [46.41.23.238])
	by mx1.freebsd.org (Postfix) with ESMTP id 0865F221F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Aug 2013 10:27:01 +0000 (UTC)
Received: by ice.42.org (Postfix, from userid 1000)
	id 3A67B2841E; Mon, 26 Aug 2013 12:20:09 +0200 (CEST)
Message-Id: <20130826102009.3A67B2841E@ice.42.org>
Date: Mon, 26 Aug 2013 12:20:09 +0200 (CEST)
From: Stefan `Sec` Zehl <sec@42.org>
Reply-To: Stefan `Sec` Zehl <sec@42.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: file(1) fails to respect -L with --mime-type
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         181544
>Category:       bin
>Synopsis:       [patch] file(1) fails to respect -L with --mime-type
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 26 10:30:06 UTC 2013
>Closed-Date:    
>Last-Modified:  Tue Aug 27 01:52:34 UTC 2013
>Originator:     Stefan `Sec` Zehl
>Release:        FreeBSD 8.4-STABLE amd64
>Organization:
>Environment:
System: FreeBSD ice 8.4-STABLE FreeBSD 8.4-STABLE #23 r252204: Tue Jun 25 14:30:35 CEST 2013 root@ice:/usr/obj/usr/src/sys/ICE amd64

FreeBSD-8 stable. From checking svnweb this problem might also exist on
FreeBSD-9, but somebody needs to confirm this.

>Description:

file (as in /usr/bin/file) does not honor "-L" when using mime type output.

As the ports makefile checks for shared library existance vie "file -L
--mime-type" = "application/x-sharedlib" this results in ports trying to
re-install already existing libraries.

>How-To-Repeat:

run file with "-L" and "--mime-type" on a symlink.

without "-L" it's ok:

ice:~>file -b --mime-type /usr/local/lib/libdb-4.2.so.2 
application/x-symlink

actual output:

ice:~>file -b -L --mime-type /usr/local/lib/libdb-4.2.so.2                   :(
application/x-symlink

expected output:

ice:~>LD_LIBRARY_PATH=/usr/obj/usr/src/lib/libmagic file -b -L --mime-type /usr/local/lib/libdb-4.2.so.2
application/x-sharedlib

>Fix:

Honestly, I'm not sure what the "&= MAGIC_MIME_TYPE" is supposed to do here,
but it actually deletes all other options from flags.

Someone with a better understanding of the code might want to check if the
code maybe was actually supposed to be "ms->flags |= MAGIC_MIME_TYPE" here?

I just added MAGIC_SYMLINK here to keep it from being deleted to fix the
problem at hand.

--- contrib/file/apprentice.c.org	2013-06-18 18:14:45.000000000 +0200
+++ contrib/file/apprentice.c	2013-08-26 12:01:20.000000000 +0200
@@ -2231,7 +2231,7 @@
 	if (ms->flags & MAGIC_MIME) {
 		asprintf(&buf, "%.*s.mime%s", (int)(q - fn), fn, ext);
 		if (access(buf, R_OK) != -1) {
-			ms->flags &= MAGIC_MIME_TYPE;
+			ms->flags &= MAGIC_MIME_TYPE | MAGIC_SYMLINK;
 			return buf;
 		}
 		free(buf);
@@ -2240,7 +2240,7 @@
 
 	/* Compatibility with old code that looked in .mime */
 	if (strstr(p, ".mime") != NULL)
-		ms->flags &= MAGIC_MIME_TYPE;
+		ms->flags &= MAGIC_MIME_TYPE | MAGIC_SYMLINK;
 	return buf;
 }
 



>Release-Note:
>Audit-Trail:
>Unformatted:
