<?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>68343</bug_id>
          
          <creation_ts>2004-10-20 21:46 0000</creation_ts>
          <short_desc>media-sound/mpg123: buffer overflows in httpget.c</short_desc>
          <delta_ts>2004-12-23 09:30:07 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>Security</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <status_whiteboard>B2 [glsa] vorlon</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>lewk@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>chriswhite@gentoo.org</cc>
    
    <cc>eradicator@gentoo.org</cc>
    
    <cc>sound@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>lewk@gentoo.org</who>
            <bug_when>2004-10-20 21:46:18 0000</bug_when>
            <thetext>*******************************
                      * Security Advisory #01, 2004 *
                      *******************************
             Carlos Barros &lt;barros [at] barrossecurity d0t com&gt;
                          www.barrossecurity.com
******************************************************************************

Title: mpg123 buffer overflows

Vulnerable package(s): 
 * mpg123-pre0.59s;
 * mpg123-0.59r.

Date: 08/10/2004

Legal notice:

This Advisory is Copyright (c) 2004 Carlos Barros.
Permission is granted for the redistribution of this alert electronically. It
may not be edited in any way without the express written consent of the 
author.

Disclaimer:

The information in the advisory is believed to be accurate at the time of 
publishing based on currently available information. Use of the information 
constitutes acceptance for use in an AS IS condition. There are no warranties 
with regard to this information. Neither the author nor the publisher accepts 
any liability for any direct, indirect, or consequential loss or damage 
arising from use of, or reliance on, this information.

Introduction:

mpg123 is a real time MPEG Audio Player for Layer 1,2 and Layer3. It can be
downloaded at: www.mpg123.de

Vulnerability details:

mpg123 is prone to a buffer overflow in the function getauthfromURL.

// httpget.c, line 114
int getauthfromURL(char *url,char *auth)
{
  char *pos;

  *auth = 0;

  if (!(strncmp(url, &quot;http://&quot;, 7)))
    url += 7;

  if( (pos = strchr(url,&apos;@&apos;)) ) {
    int i;
    for(i=0;i&lt;pos-url;i++) {
      if( url[i] == &apos;/&apos; )
         return 0;
    }
    strncpy(auth,url,pos-url);  &lt;-- HERE
    auth[pos-url] = 0;
    strcpy(url,pos+1);
    return 1;
  }
  return 0;
}

This function is called by http_open(), line 225 from httpget.c, and passes
&quot;purl&quot; and &quot;httpauth1&quot; as parameters. purl is a dinamic allocated variable
and httpauth1 is a static (global) var with a fixed length of 256. As you
can see, getauthfromURL function copies the purl string, until a @, into
httpauth1 without checking the length. I was not able to exploit this vuln
successfull to execute arbitraty code (too lazy), but I think it is not
impossible. httpauth1 can overwrite some useful address and it is appended
into a dinamic allocated variable (request) after a base64 encoding, 
overflowing this var too. 

if (strlen(httpauth1) || httpauth) {
  char buf[1023];
  strcat (request,&quot;Authorization: Basic &quot;);
  if(strlen(httpauth1))
    encode64(httpauth1,buf);
  else
    encode64(httpauth,buf);
  strcat (request,buf); &lt;-- HERE
  strcat (request,&quot;\r\n&quot;);
}

This vulnerability can be trigged locally via
 mpg123 -@ http://AAAAAAAAAAAAAA...AAAAA@www.somesite.com/somefile.xxx,
or remotely via crafted playlist with some file formatted as shown above.

There is another buffer overflow in the function http_open. At line 245 of
httpget.c,the prgName variable (mpg123 filename) is appended into the request 
variable. 

  sprintf (request + strlen(request),
     &quot; HTTP/1.0\r\nUser-Agent: %s/%s\r\n&quot;,
     prgName, prgVersion);

The length of this variable is not checked, so, one can create a 
specially crafted symlink to overflow the request variable. It is not a 
serious bug cause it can be only exploited locally and mpg123 is not SUID by 
default.

Timeline:

02/10/2004: Vulnerability detected.
10/10/2004: Vendor contacted. No response.
20/10/2004: Public available

******************************************************************************</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-10-21 02:58:45 0000</bug_when>
            <thetext>No confirmation from upstream</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-10-21 03:04:01 0000</bug_when>
            <thetext>Upstream is dead.  I don&apos;t have time to look at this now.  I&apos;ll try to look at it tomorrow.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>chriswhite@gentoo.org</who>
            <bug_when>2004-10-21 08:18:43 0000</bug_when>
            <thetext>eradicator:

 I was working on this bug last night, but didn&apos;t get a chance to fix
it fully.  It seems there&apos;s a bit of a stability issues besides the security
fix that needs to be applied.  If you can look at it and get things done 
faster, please feel free to take it, otherwise I&apos;ll keep working on it.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-10-21 12:39:47 0000</bug_when>
            <thetext>the stability issues are documented in other bugs, and we shouldn&apos;t worry about fixing those at the same time as this security fix.  I&apos;m on this now and will hopefully have a releasse soon</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-10-21 14:01:01 0000</bug_when>
            <thetext>mpg123-0.59s-r5 is fixed.  the size of httpauth1 is upperbound by strlen(purl) + 1, so we allocate that much space.  Likewise for buf, we allocate (strlen(httpauth) + 1) * 4

Archs, please test and mark stable.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rajiv@gentoo.org</who>
            <bug_when>2004-10-21 16:52:16 0000</bug_when>
            <thetext>tried to emerge media-sound/mpg123-0.59s-r5 but the gentoo patch is not on any mirrors
that i tried and the original src is bad:

 &gt;&gt;&gt; emerge (1 of 1) media-sound/mpg123-0.59s-r5 to /
[...]
&gt;&gt;&gt; Downloading http://dev.gentoo.org/~eradicator/mpg123/mpg123-0.59s-gentoo-1.0.tar.bz2
--19:49:21--  http://dev.gentoo.org/%7Eeradicator/mpg123/mpg123-0.59s-gentoo-1.0.tar.bz2
           =&gt; `/usr/portage/distfiles/mpg123-0.59s-gentoo-1.0.tar.bz2&apos;
Resolving dev.gentoo.org... 156.56.111.197
Connecting to dev.gentoo.org[156.56.111.197]:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
19:49:21 ERROR 403: Forbidden.


eradicator: please chmod a+r that file. thanks.

</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-10-21 17:11:34 0000</bug_when>
            <thetext>done, sorry</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>josejx@gentoo.org</who>
            <bug_when>2004-10-21 18:19:16 0000</bug_when>
            <thetext>Marked ppc stable.  The patchdir variable was also wrong, so I fixed that too.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-10-22 13:21:33 0000</bug_when>
            <thetext>Just the following need to mark it stable
~ia64
~alpha
~mips
~ppc64

IIRC, they&apos;re all tier-2 archs, so we can put out the GLSA.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kloeri@gentoo.org</who>
            <bug_when>2004-10-22 13:59:40 0000</bug_when>
            <thetext>Stable on alpha.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-10-22 14:05:02 0000</bug_when>
            <thetext>Ready for a GLSA</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vorlon@gentoo.org</who>
            <bug_when>2004-10-25 01:29:03 0000</bug_when>
            <thetext>Eradicator, could you comment on the other bug mentioned in the advisory? It doesn&apos;t appear to be fixed with the new patch.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vorlon@gentoo.org</who>
            <bug_when>2004-10-25 02:24:25 0000</bug_when>
            <thetext>Eradicator confirmed that a patch is missing for that.
Could someone pls look into it?

going back to ebuild status and removing arches for now</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-10-25 15:26:31 0000</bug_when>
            <thetext>ok, -r6 has been added which addresses all 3 security fixes.  The changes to fix the last bug found that buffer overflows could easily result from more than just the prgName variable.  The httpauth lengths were not considered, and the proxy server was not considered.  This is now fixed now by allocating the corerct size to request.

Archs, please test -r6.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>josejx@gentoo.org</who>
            <bug_when>2004-10-25 16:01:05 0000</bug_when>
            <thetext>Tested and marked stable on ppc.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kloeri@gentoo.org</who>
            <bug_when>2004-10-25 17:54:33 0000</bug_when>
            <thetext>-r6 stable on alpha.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>klieber@gentoo.org</who>
            <bug_when>2004-10-27 05:26:44 0000</bug_when>
            <thetext>glsa 20041027</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>tgall@gentoo.org</who>
            <bug_when>2004-10-30 08:55:17 0000</bug_when>
            <thetext>stable on ppc64, </thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rene.rheaume@videotron.qc.ca</who>
            <bug_when>2004-11-04 05:29:18 0000</bug_when>
            <thetext>Could this vulnerability affect the MP3 plugin based on mpg123 included in XMMS and Beep Media Player?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>eradicator@gentoo.org</who>
            <bug_when>2004-11-04 13:00:55 0000</bug_when>
            <thetext>re: comment #19:

no</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hardave@gentoo.org</who>
            <bug_when>2004-11-08 01:13:04 0000</bug_when>
            <thetext>Stable on mips.</thetext>
          </long_desc>
      
    </bug>

</bugzilla>