~ubuntu-branches/ubuntu/raring/sudo/raring

« back to all changes in this revision

Viewing changes to zlib/gzwrite.c

  • Committer: Package Import Robot
  • Author(s): Tyler Hicks
  • Date: 2012-07-16 14:01:42 UTC
  • mfrom: (1.3.22 sid)
  • Revision ID: package-import@ubuntu.com-20120716140142-b0tgau0k6nid4mrf
Tags: 1.8.5p2-1ubuntu1
* Merge from debian/testing (LP: #1024154), remaining changes:
  - debian/patches/keep_home_by_default.patch:
    + Set HOME in initial_keepenv_table.
  - debian/rules:
    + compile with --without-lecture --with-tty-tickets (Ubuntu specific)
    + install man/man8/sudo_root.8 in both flavours (Ubuntu specific)
    + install apport hooks
    + The ubuntu-sudo-as-admin-successful.patch was taken upstream by
      Debian however it requires a --enable-admin-flag configure flag to
      actually enable it in both flavours.
  - debian/control:
    + Mark Debian Vcs-* as XS-Debian-Vcs-*
    + update debian/control
  - debian/sudoers:
    + grant admin group sudo access
  - debian/source_sudo.py, debian/sudo-ldap.dirs, debian/sudo.dirs:
    + add usr/share/apport/package-hooks
  - debian/sudo.pam:
    + Use pam_env to read /etc/environment and /etc/default/locale
      environment files. Reading ~/.pam_environment is not permitted due to
      security reasons.
* Dropped changes:
  - debian/patches/lp927828-fix-abort-in-pam-modules-when-timestamp-valid.patch
    + Fixed upstream in 1.8.5
  - debian/patches/CVE-2012-2337.patch:
    + Fixed upstream in 1.8.4p5
  - debian/patches/pam_env_merge.patch:
    + Feature released upstream in 1.8.5
  - debian/{sudo,sudo-ldap}.{preinst,postinst,postrm}:
    + Drop Ubuntu-specific sudoers file migration code because the only
      upgrade path to quantal is from precise. All necessary sudoers file
      migration will have already been done by the time this version of the
      sudo package is installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* gzwrite.c -- zlib functions for writing gzip files
2
 
 * Copyright (C) 2004, 2005, 2010 Mark Adler
 
2
 * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
3
3
 * For conditions of distribution and use, see copyright notice in zlib.h
4
4
 */
5
5
 
18
18
    int ret;
19
19
    z_streamp strm = &(state->strm);
20
20
 
21
 
    /* allocate input and output buffers */
 
21
    /* allocate input buffer */
22
22
    state->in = malloc(state->want);
23
 
    state->out = malloc(state->want);
24
 
    if (state->in == NULL || state->out == NULL) {
25
 
        if (state->out != NULL)
 
23
    if (state->in == NULL) {
 
24
        gz_error(state, Z_MEM_ERROR, "out of memory");
 
25
        return -1;
 
26
    }
 
27
 
 
28
    /* only need output buffer and deflate state if compressing */
 
29
    if (!state->direct) {
 
30
        /* allocate output buffer */
 
31
        state->out = malloc(state->want);
 
32
        if (state->out == NULL) {
 
33
            free(state->in);
 
34
            gz_error(state, Z_MEM_ERROR, "out of memory");
 
35
            return -1;
 
36
        }
 
37
 
 
38
        /* allocate deflate memory, set up for gzip compression */
 
39
        strm->zalloc = Z_NULL;
 
40
        strm->zfree = Z_NULL;
 
41
        strm->opaque = Z_NULL;
 
42
        ret = deflateInit2(strm, state->level, Z_DEFLATED,
 
43
                           MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
 
44
        if (ret != Z_OK) {
26
45
            free(state->out);
27
 
        if (state->in != NULL)
28
46
            free(state->in);
29
 
        gz_error(state, Z_MEM_ERROR, "out of memory");
30
 
        return -1;
31
 
    }
32
 
 
33
 
    /* allocate deflate memory, set up for gzip compression */
34
 
    strm->zalloc = Z_NULL;
35
 
    strm->zfree = Z_NULL;
36
 
    strm->opaque = Z_NULL;
37
 
    ret = deflateInit2(strm, state->level, Z_DEFLATED,
38
 
                       15 + 16, 8, state->strategy);
39
 
    if (ret != Z_OK) {
40
 
        free(state->in);
41
 
        gz_error(state, Z_MEM_ERROR, "out of memory");
42
 
        return -1;
 
47
            gz_error(state, Z_MEM_ERROR, "out of memory");
 
48
            return -1;
 
49
        }
43
50
    }
44
51
 
45
52
    /* mark state as initialized */
46
53
    state->size = state->want;
47
54
 
48
 
    /* initialize write buffer */
49
 
    strm->avail_out = state->size;
50
 
    strm->next_out = state->out;
51
 
    state->next = strm->next_out;
 
55
    /* initialize write buffer if compressing */
 
56
    if (!state->direct) {
 
57
        strm->avail_out = state->size;
 
58
        strm->next_out = state->out;
 
59
        state->x.next = strm->next_out;
 
60
    }
52
61
    return 0;
53
62
}
54
63
 
55
64
/* Compress whatever is at avail_in and next_in and write to the output file.
56
65
   Return -1 if there is an error writing to the output file, otherwise 0.
57
66
   flush is assumed to be a valid deflate() flush value.  If flush is Z_FINISH,
58
 
   then the deflate() state is reset to start a new gzip stream. */
 
67
   then the deflate() state is reset to start a new gzip stream.  If gz->direct
 
68
   is true, then simply write to the output file without compressing, and
 
69
   ignore flush. */
59
70
local int gz_comp(state, flush)
60
71
    gz_statep state;
61
72
    int flush;
68
79
    if (state->size == 0 && gz_init(state) == -1)
69
80
        return -1;
70
81
 
 
82
    /* write directly if requested */
 
83
    if (state->direct) {
 
84
        got = write(state->fd, strm->next_in, strm->avail_in);
 
85
        if (got < 0 || (unsigned)got != strm->avail_in) {
 
86
            gz_error(state, Z_ERRNO, zstrerror());
 
87
            return -1;
 
88
        }
 
89
        strm->avail_in = 0;
 
90
        return 0;
 
91
    }
 
92
 
71
93
    /* run deflate() on provided input until it produces no more output */
72
94
    ret = Z_OK;
73
95
    do {
75
97
           doing Z_FINISH then don't write until we get to Z_STREAM_END */
76
98
        if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
77
99
            (flush != Z_FINISH || ret == Z_STREAM_END))) {
78
 
            have = (unsigned)(strm->next_out - state->next);
79
 
            if (have && ((got = write(state->fd, state->next, have)) < 0 ||
 
100
            have = (unsigned)(strm->next_out - state->x.next);
 
101
            if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
80
102
                         (unsigned)got != have)) {
81
103
                gz_error(state, Z_ERRNO, zstrerror());
82
104
                return -1;
85
107
                strm->avail_out = state->size;
86
108
                strm->next_out = state->out;
87
109
            }
88
 
            state->next = strm->next_out;
 
110
            state->x.next = strm->next_out;
89
111
        }
90
112
 
91
113
        /* compress */
131
153
        }
132
154
        strm->avail_in = n;
133
155
        strm->next_in = state->in;
134
 
        state->pos += n;
 
156
        state->x.pos += n;
135
157
        if (gz_comp(state, Z_NO_FLUSH) == -1)
136
158
            return -1;
137
159
        len -= n;
163
185
    /* since an int is returned, make sure len fits in one, otherwise return
164
186
       with an error (this avoids the flaw in the interface) */
165
187
    if ((int)len < 0) {
166
 
        gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
 
188
        gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
167
189
        return 0;
168
190
    }
169
191
 
193
215
                n = len;
194
216
            memcpy(strm->next_in + strm->avail_in, buf, n);
195
217
            strm->avail_in += n;
196
 
            state->pos += n;
 
218
            state->x.pos += n;
197
219
            buf = (char *)buf + n;
198
220
            len -= n;
199
221
            if (len && gz_comp(state, Z_NO_FLUSH) == -1)
208
230
        /* directly compress user buffer to file */
209
231
        strm->avail_in = len;
210
232
        strm->next_in = (voidp)buf;
211
 
        state->pos += len;
 
233
        state->x.pos += len;
212
234
        if (gz_comp(state, Z_NO_FLUSH) == -1)
213
235
            return 0;
214
236
    }
249
271
        if (strm->avail_in == 0)
250
272
            strm->next_in = state->in;
251
273
        strm->next_in[strm->avail_in++] = c;
252
 
        state->pos++;
253
 
        return c;
 
274
        state->x.pos++;
 
275
        return c & 0xff;
254
276
    }
255
277
 
256
278
    /* no room in buffer or not initialized, use gz_write() */
257
279
    buf[0] = c;
258
280
    if (gzwrite(file, buf, 1) != 1)
259
281
        return -1;
260
 
    return c;
 
282
    return c & 0xff;
261
283
}
262
284
 
263
285
/* -- see zlib.h -- */
274
296
    return ret == 0 && len != 0 ? -1 : ret;
275
297
}
276
298
 
277
 
#ifdef STDC
 
299
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
278
300
#include <stdarg.h>
279
301
 
280
302
/* -- see zlib.h -- */
342
364
    /* update buffer and position, defer compression until needed */
343
365
    strm->avail_in = (unsigned)len;
344
366
    strm->next_in = state->in;
345
 
    state->pos += len;
 
367
    state->x.pos += len;
346
368
    return len;
347
369
}
348
370
 
349
 
#else /* !STDC */
 
371
#else /* !STDC && !Z_HAVE_STDARG_H */
350
372
 
351
373
/* -- see zlib.h -- */
352
374
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
366
388
    state = (gz_statep)file;
367
389
    strm = &(state->strm);
368
390
 
 
391
    /* check that can really pass pointer in ints */
 
392
    if (sizeof(int) != sizeof(void *))
 
393
        return 0;
 
394
 
369
395
    /* check that we're writing and that there's no error */
370
396
    if (state->mode != GZ_WRITE || state->err != Z_OK)
371
397
        return 0;
416
442
    /* update buffer and position, defer compression until needed */
417
443
    strm->avail_in = (unsigned)len;
418
444
    strm->next_in = state->in;
419
 
    state->pos += len;
 
445
    state->x.pos += len;
420
446
    return len;
421
447
}
422
448
 
500
526
int ZEXPORT gzclose_w(file)
501
527
    gzFile file;
502
528
{
503
 
    int ret = 0;
 
529
    int ret = Z_OK;
504
530
    gz_statep state;
505
531
 
506
532
    /* get internal structure */
515
541
    /* check for seek request */
516
542
    if (state->seek) {
517
543
        state->seek = 0;
518
 
        ret += gz_zero(state, state->skip);
 
544
        if (gz_zero(state, state->skip) == -1)
 
545
            ret = state->err;
519
546
    }
520
547
 
521
548
    /* flush, free memory, and close file */
522
 
    ret += gz_comp(state, Z_FINISH);
523
 
    (void)deflateEnd(&(state->strm));
524
 
    free(state->out);
 
549
    if (gz_comp(state, Z_FINISH) == -1)
 
550
        ret = state->err;
 
551
    if (!state->direct) {
 
552
        (void)deflateEnd(&(state->strm));
 
553
        free(state->out);
 
554
    }
525
555
    free(state->in);
526
556
    gz_error(state, Z_OK, NULL);
527
557
    free(state->path);
528
 
    ret += close(state->fd);
 
558
    if (close(state->fd) == -1)
 
559
        ret = Z_ERRNO;
529
560
    free(state);
530
 
    return ret ? Z_ERRNO : Z_OK;
 
561
    return ret;
 
562
}
 
563
 
 
564
/* used by zlibVersion() to get the vsnprintf story from the horse's mouth */
 
565
unsigned long ZEXPORT gzflags()
 
566
{
 
567
    unsigned long flags = 0;
 
568
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
 
569
#  ifdef NO_vsnprintf
 
570
    flags += 1L << 25;
 
571
#    ifdef HAS_vsprintf_void
 
572
    flags += 1L << 26;
 
573
#    endif
 
574
#  else
 
575
#    ifdef HAS_vsnprintf_void
 
576
    flags += 1L << 26;
 
577
#    endif
 
578
#  endif
 
579
#else
 
580
    flags += 1L << 24;
 
581
#  ifdef NO_snprintf
 
582
    flags += 1L << 25;
 
583
#    ifdef HAS_sprintf_void
 
584
    flags += 1L << 26;
 
585
#    endif
 
586
#  else
 
587
#    ifdef HAS_snprintf_void
 
588
    flags += 1L << 26;
 
589
#    endif
 
590
#  endif
 
591
#endif
 
592
    return flags;
531
593
}