<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>163948</bug_id>
          
          <creation_ts>2007-01-26 18:17 0000</creation_ts>
          <short_desc>sys-apps/file-4.18 doesn&apos;t NULLify file in struct magic_set</short_desc>
          <delta_ts>2007-02-07 04:50:17 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Linux</product>
          <component>Core system</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          
          <priority>P2</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>sqrammi@hotmail.com</reporter>
          <assigned_to>base-system@gentoo.org</assigned_to>
          

      

      
          <long_desc isprivate="0">
            <who>sqrammi@hotmail.com</who>
            <bug_when>2007-01-26 18:17:09 0000</bug_when>
            <thetext>When a new struct magic_set is created as the handle to the calling application (in magic_open), the &quot;file&quot; char * is not NULLified.  This causes unexplained segfaults in other apps that don&apos;t properly have their magic.mgc file created, i.e. in app-arch/rpm-4.4.6-r3.  The file pointer is some random value, so when file_magwarn tries to report a missing magic.mgc file, for example, it tries to print ms-&gt;file, which is NULL, and the segfault occurs.

I have submitted a patch that fixes the problem and allows file to properly tell the user that they are missing a magic.mgc file, instead of just crashing outright.  We could also just bzero the struct magic_set after it is malloc&apos;ed.


Reproducible: Always

Steps to Reproduce:
1. Try to build an rpm using rpmbuild with the current portage tree.  It segfaults with no explanation.
2. Or just try to use any app that uses magic_open on an unexisting magic.mgc file, it will segfault.

Hopefully you won&apos;t need to reproduce the problem, though.  It&apos;s just bad practice in file&apos;s &quot;magic.c&quot; source code to not initialize the pointer properly, and then expect it to be set when an error occurs.




--- src/magic.c.orig	2007-01-26 11:00:41.310878002 -0700
+++ src/magic.c	2007-01-26 10:42:51.569916935 -0700
@@ -110,6 +110,7 @@
 	ms-&gt;haderr = 0;
 	ms-&gt;error = -1;
 	ms-&gt;mlist = NULL;
+	ms-&gt;file = NULL;
 	return ms;
 free3:
 	free(ms-&gt;o.pbuf);</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2007-02-07 04:50:17 0000</bug_when>
            <thetext>looks sane to me ... added to 4.19-r1 and mailed upstream, cheers</thetext>
          </long_desc>
      
    </bug>

</bugzilla>