]> git.pld-linux.org Git - packages/poldek.git/blob - poldek-cookie.patch
- slower but safer version
[packages/poldek.git] / poldek-cookie.patch
1 diff -urN poldek-0.18.8.org/pkgfl.c poldek-0.18.8/pkgfl.c
2 --- poldek-0.18.8.org/pkgfl.c   2004-12-30 13:05:22.000000000 +0100
3 +++ poldek-0.18.8/pkgfl.c       2005-04-21 22:06:58.126819592 +0200
4 @@ -530,7 +530,7 @@
5      tn_buf *nbuf;
6      tn_buf_it nbufi;
7      uint32_t size;
8 -    char *buf;
9 +    char *buf, dummy;
10      
11      if (fread(&size, sizeof(size), 1, stream) != 1)
12          return NULL;
13 @@ -548,7 +548,7 @@
14      fl = pkgfl_restore(&nbufi, dirs, include);
15      n_buf_free(nbuf);
16      
17 -    fseek(stream, 1, SEEK_CUR); /* skip final '\n' */
18 +    fread(&dummy, 1, 1, stream); /* skip final '\n' */
19  
20      return fl;
21  }
22 @@ -557,12 +557,18 @@
23  int pkgfl_skip_f(FILE *stream) 
24  {
25      uint32_t size;
26 +    char *buf;
27      
28      if (fread(&size, sizeof(size), 1, stream) != 1)
29          return 0;
30      
31      size = ntoh32(size);
32 -    fseek(stream, size + 1, SEEK_CUR);
33 +    buf = malloc(size + 1);
34 +    if (buf)
35 +       fread(buf, 1, size + 1, stream);
36 +    else
37 +       fseek(stream, size + 1, SEEK_CUR);
38 +    free(buf);
39      return 1;
40  }
41  
42 diff -urN poldek-0.18.8.org/pkgu.c poldek-0.18.8/pkgu.c
43 --- poldek-0.18.8.org/pkgu.c    2002-05-15 17:42:48.000000000 +0200
44 +++ poldek-0.18.8/pkgu.c        2005-04-21 22:04:22.641456960 +0200
45 @@ -239,8 +239,8 @@
46  {
47      uint16_t nsize, nlangs;
48  
49 -    fseek(stream, sizeof(nlangs), SEEK_CUR);
50 -    if (fread(&nsize, sizeof(nsize), 1, stream) != 1) {
51 +    if ((fread(&nlangs, sizeof(nlangs), 1, stream) != 1) ||
52 +       (fread(&nsize, sizeof(nsize), 1, stream) != 1)) {
53          nsize = 0;
54      } else {
55          nsize = ntoh16(nsize);
56 diff -urN poldek-0.18.8.org/trurlib/nstream.c poldek-0.18.8/trurlib/nstream.c
57 --- poldek-0.18.8.org/trurlib/nstream.c 2004-05-06 09:57:45.000000000 +0200
58 +++ poldek-0.18.8/trurlib/nstream.c     2005-04-21 22:04:22.622459848 +0200
59 @@ -57,8 +57,10 @@
60      z_off_t rc, off = *offset;
61      
62      rc = gzseek(stream, off, whence);
63 -    if (rc >= 0)
64 +    if (rc >= 0) {
65 +       *offset = rc;
66          rc = 0;
67 +    }
68  #if ZLIB_TRACE
69      printf("zfseek (%p, %ld, %lld, %d) = %d\n", stream, off, *offset, whence, rc);
70  #endif    
71 @@ -281,7 +283,7 @@
72                      
73                  } else {
74                      st->stream = stream;
75 -                    fseek(st->stream, 0, SEEK_SET); /* glibc BUG (?) */
76 +                    fseek(st->stream, 0, SEEK_SET); /* XXX glibc BUG (?) */
77                      st->type = type;
78                  };
79                  break;
80 diff -urN poldek-0.18.8.org/vfile/vfile.c poldek-0.18.8/vfile/vfile.c
81 --- poldek-0.18.8.org/vfile/vfile.c     2004-02-26 19:22:28.000000000 +0100
82 +++ poldek-0.18.8/vfile/vfile.c 2005-04-21 22:04:22.630458632 +0200
83 @@ -129,8 +129,10 @@
84      z_off_t rc, off = *offset;
85      
86      rc = gzseek(stream, off, whence);
87 -    if (rc >= 0)
88 +    if (rc >= 0) {
89 +       *offset = rc;
90          rc = 0;
91 +    }
92  #if ZLIB_TRACE
93      printf("zfseek (%p, %ld, %lld, %d) = %d\n", stream, off, *offset, whence, rc);
94  #endif    
95 @@ -344,7 +346,16 @@
96                  vf->vf_stream = fopencookie(gzstream, mode, gzio_cookie);
97                  if (vf->vf_stream != NULL) {
98                      rc = 1;
99 -                    fseek(vf->vf_stream, 0, SEEK_SET); /* glibc BUG (?) */
100 +                   vf->vf_buf = malloc(128); /* use small buffer to avoid reverse gzseeks on small forward fseeks */
101 +                   if(vf->vf_buf == NULL)
102 +                       vfile_err_fn("buffer malloc failed for %s\n", CL_URL(path));
103 +                   else
104 +                       if(setvbuf(vf->vf_stream, vf->vf_buf, _IOFBF, 128) != 0) {
105 +                           vfile_err_fn("setvbuf failed for %s\n", CL_URL(path));
106 +                           free(vf->vf_buf);
107 +                           vf->vf_buf = NULL;
108 +                       }
109 +                    fseek(vf->vf_stream, 0, SEEK_SET); /* XXX glibc BUG (?) */
110                  } else
111                      vfile_err_fn("fopencookie %s: hgw error\n", CL_URL(path));
112  
113 @@ -484,6 +495,7 @@
114      vf.vf_type = vftype;
115      vf.vf_mode = vfmode;
116      vf.vf_flags = 0;
117 +    vf.vf_buf = NULL;
118      
119      urltype = vf_url_type(path);
120      opened = 0;
121 @@ -681,6 +693,8 @@
122          free(vf->vf_tmpath);
123          vf->vf_tmpath = NULL;
124      }
125 +    if (vf->vf_buf)
126 +       free(vf->vf_buf);
127      memset(vf, 0, sizeof(*vf));
128      free(vf);
129  }
130 diff -urN poldek-0.18.8.org/vfile/vfile.h poldek-0.18.8/vfile/vfile.h
131 --- poldek-0.18.8.org/vfile/vfile.h     2004-06-08 15:57:03.000000000 +0200
132 +++ poldek-0.18.8/vfile/vfile.h 2005-04-21 22:04:22.634458024 +0200
133 @@ -81,6 +81,7 @@
134  
135      char          *vf_path;
136      char          *vf_tmpath;
137 +    char          *vf_buf;
138      int16_t       _refcnt;
139  };
140  
This page took 0.110334 seconds and 3 git commands to generate.