Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 98942 - net-p2p/ctorrent: maybe stack oveflow _btf_recurses_directory() function
Summary: net-p2p/ctorrent: maybe stack oveflow _btf_recurses_directory() function
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Auditing (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Security
URL:
Whiteboard: jaervosz
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-13 18:17 UTC by solar (RETIRED)
Modified: 2005-09-02 02:42 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description solar (RETIRED) gentoo-dev 2005-07-13 18:17:09 UTC
A user had submitted a patch for ctorrent which came from openembedded.
bug #98929 While reviewing the patch I noticed that one of things
included in it was an update for the getwd() function to use getcwd().
Upon further investigation it's pretty clear that it's very easy to
overflow in the btFiles::_btf_recurses_directory() function. The likely
hood of it overflowing in real life situations I have no idea. I've
never used this software in my life and really have no desire to.

Example of how such code can be overflowed is as.

#include <unistd.h>
#define MAXPATHLEN 1024

int recurses_directory(char *cur_path)
{
  char full_cur[MAXPATHLEN];
  char fn[MAXPATHLEN];

  if( !getwd(full_cur) ) return -1;

  if( cur_path )
    strcpy(fn, full_cur);

  return 0;
}

int main() {
  int i;
  for (i = 0; i != MAXPATHLEN+16; i++) {
        mkdir("A", 0755);
        chdir("A");
  }
  recurses_directory(NULL);
  return 0;
}

I think there are probably a few other problems with this package as I
see unchecked strcpy() calls with fixed size buffers all over the place.
I'm not really wanting to invest anymore of my time on it as my vote would be for preemptive p.mask/removal. If any of our auditors wishes to audit feel free.
Comment 1 SpanKY gentoo-dev 2005-07-13 18:30:38 UTC
the patch in question is on Bug 98929

http://bugs.gentoo.org/attachment.cgi?id=63343&action=view
Comment 2 Thierry Carrez (RETIRED) gentoo-dev 2005-07-14 03:45:22 UTC
Not sure it's a good idea to patch only the one we saw. This needs a full audit
or a removal. And we should perhaps package.mask it until this is done ?

net-p2p : what's your position on this package ?
Comment 3 Tavis Ormandy (RETIRED) gentoo-dev 2005-07-14 05:04:19 UTC
yeah, but you're example is only wrong as you've defined MAXPATHLEN as 1024, 
when the MAXPATHLEN on your system is longer. a cursory glance suggests ctorrent 
is using the limits.h definition, so creating a longer path is not possible...

Looks safe to me, but Rob is the C++ auditor...any opinion Rob? :)
Comment 4 solar (RETIRED) gentoo-dev 2005-07-14 05:36:15 UTC
Ahh your right tavis. that 1024 came from within an #ifdef WINDOWS
Changing Component to Auditing and downgrading Severity
Comment 5 rob holland (RETIRED) gentoo-dev 2005-08-01 00:53:02 UTC
Seems ok to me. I'd like to have a little more time to check the other code
though, so please leave the bug open for a little bit.
Comment 6 rob holland (RETIRED) gentoo-dev 2005-09-02 02:42:58 UTC
don't really have time for this right now, the issue the bug was filed for seems
not to be a concern, so I'll just close.