]> git.pld-linux.org Git - packages/ctorrent.git/blob - ctorrent-CVE-2009-1759.patch
rebuild with openssl 3.0.0
[packages/ctorrent.git] / ctorrent-CVE-2009-1759.patch
1 Index: bencode.h
2 ===================================================================
3 --- bencode.h   (revision 301)
4 +++ bencode.h   (revision 302)
5 @@ -25,7 +25,7 @@
6  size_t decode_list(const char *b,size_t len,const char *keylist);
7  size_t decode_rev(const char *b,size_t len,const char *keylist);
8  size_t decode_query(const char *b,size_t len,const char *keylist,const char **ps,size_t *pi,int64_t *pl,int method);
9 -size_t decode_list2path(const char *b, size_t n, char *pathname);
10 +size_t decode_list2path(const char *b, size_t n, char *pathname, size_t maxlen);
11  size_t bencode_buf(const char *str,size_t len,FILE *fp);
12  size_t bencode_str(const char *str, FILE *fp);
13  size_t bencode_int(const uint64_t integer, FILE *fp);
14 Index: bencode.cpp
15 ===================================================================
16 --- bencode.cpp (revision 301)
17 +++ bencode.cpp (revision 302)
18 @@ -233,22 +233,28 @@
19    return bencode_end_dict_list(fp);
20  }
21  
22 -size_t decode_list2path(const char *b, size_t n, char *pathname)
23 +size_t decode_list2path(const char *b, size_t n, char *pathname, size_t maxlen)
24  {
25    const char *pb = b;
26    const char *s = (char *) 0;
27 +  const char *endmax = pathname + maxlen - 1;
28    size_t r,q;
29  
30    if( 'l' != *pb ) return 0;
31    pb++;
32    n--;
33    if( !n ) return 0;
34 -  for(; n;){
35 +  while( n && pathname < endmax ){
36      if(!(r = buf_str(pb, n, &s, &q)) ) return 0;
37 +    if( q >= maxlen ) return 0;
38      memcpy(pathname, s, q);
39      pathname += q;
40 -    pb += r; n -= r; 
41 -    if( 'e' != *pb ){*pathname = PATH_SP, pathname++;} else break;
42 +    maxlen -= q;
43 +    pb += r;
44 +    n -= r; 
45 +    if( 'e' == *pb ) break;
46 +    if( pathname >= endmax ) return 0;
47 +    *pathname++ = PATH_SP;
48    }
49    *pathname = '\0';
50    return (pb - b + 1);
51 Index: btfiles.cpp
52 ===================================================================
53 --- btfiles.cpp (revision 301)
54 +++ btfiles.cpp (revision 302)
55 @@ -471,6 +471,8 @@
56      BTFILE *pbf_last = (BTFILE*) 0; 
57      BTFILE *pbf = (BTFILE*) 0;
58      size_t dl;
59 +    unsigned long nfiles = 0;
60 +
61      if( decode_query(metabuf,metabuf_len,"info|length",
62                      (const char**) 0,(size_t*) 0,(int64_t*) 0,QUERY_LONG) )
63        return -1;
64 @@ -524,12 +526,18 @@
65  #ifndef WINDOWS
66        if( !pbf ) return -1;
67  #endif
68 +      nfiles++;
69        pbf->bf_length = t;
70        m_total_files_length += t;
71        r = decode_query(p, dl, "path", (const char **)0, &n, (int64_t*)0,
72                         QUERY_POS);
73 -      if( !r ) return -1;
74 -      if(!decode_list2path(p + r, n, path)) return -1;
75 +      if( !r || !decode_list2path(p + r, n, path, sizeof(path)) ){
76 +        CONSOLE.Warning(1,
77 +          "error, invalid path in torrent data for file %lu at offset %llu",
78 +          nfiles, m_total_files_length - t);
79 +        delete pbf;
80 +        return -1;
81 +      }
82  
83        int f_conv;
84        char *tmpfn = new char[strlen(path)*2+5];
This page took 0.103977 seconds and 3 git commands to generate.