--- embedaddon/php/ext/fileinfo/libmagic/compress.c 2012/02/21 23:47:56 1.1.1.1 +++ embedaddon/php/ext/fileinfo/libmagic/compress.c 2013/07/22 01:31:50 1.1.1.3 @@ -36,7 +36,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.63 2009/03/23 14:21:51 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.70 2012/11/07 17:54:48 christos Exp $") #endif #include "magic.h" @@ -84,6 +84,7 @@ private const struct { { "BZh", 3, { "bzip2", "-cd", NULL }, 1 }, /* bzip2-ed */ { "LZIP", 4, { "lzip", "-cdq", NULL }, 1 }, { "\3757zXZ\0",6,{ "xz", "-cd", NULL }, 1 }, /* XZ Utils */ + { "LRZI", 4, { "lrzip", "-dqo-", NULL }, 1 }, /* LRZIP */ }; #define NODATA ((size_t)~0) @@ -146,14 +147,13 @@ error: return rv; } #endif - /* * `safe' write for sockets and pipes. */ private ssize_t swrite(int fd, const void *buf, size_t n) { - int rv; + ssize_t rv; size_t rn = n; do @@ -164,7 +164,7 @@ swrite(int fd, const void *buf, size_t n) return -1; default: n -= rv; - buf = ((const char *)buf) + rv; + buf = CAST(const char *, buf) + rv; break; } while (n > 0); @@ -178,7 +178,7 @@ swrite(int fd, const void *buf, size_t n) protected ssize_t sread(int fd, void *buf, size_t n, int canbepipe) { - int rv; + ssize_t rv; #ifdef FIONREAD int t = 0; #endif @@ -188,9 +188,9 @@ sread(int fd, void *buf, size_t n, int canbepipe) goto nocheck; #ifdef FIONREAD - if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) { + if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1 || t == 0)) { #ifdef FD_ZERO - int cnt; + ssize_t cnt; for (cnt = 0;; cnt++) { fd_set check; struct timeval tout = {0, 100 * 1000}; @@ -224,7 +224,7 @@ sread(int fd, void *buf, size_t n, int canbepipe) nocheck: do - switch ((rv = read(fd, buf, n))) { + switch ((rv = FINFO_READ_FUNC(fd, buf, n))) { case -1: if (errno == EINTR) continue; @@ -245,7 +245,8 @@ file_pipe2file(struct magic_set *ms, int fd, const voi size_t nbytes) { char buf[4096]; - int r, tfd; + ssize_t r; + int tfd; (void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf); #ifndef HAVE_MKSTEMP @@ -257,10 +258,13 @@ file_pipe2file(struct magic_set *ms, int fd, const voi errno = r; } #else - tfd = mkstemp(buf); - r = errno; - (void)unlink(buf); - errno = r; + { + int te; + tfd = mkstemp(buf); + te = errno; + (void)unlink(buf); + errno = te; + } #endif if (tfd == -1) { file_error(ms, errno, @@ -297,7 +301,7 @@ file_pipe2file(struct magic_set *ms, int fd, const voi return -1; } (void)close(tfd); - if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) { + if (FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) { file_badseek(ms); return -1; } @@ -312,7 +316,6 @@ file_pipe2file(struct magic_set *ms, int fd, const voi #define FNAME (1 << 3) #define FCOMMENT (1 << 4) - private size_t uncompressgzipped(struct magic_set *ms, const unsigned char *old, unsigned char **newch, size_t n) @@ -342,18 +345,21 @@ uncompressgzipped(struct magic_set *ms, const unsigned if (data_start >= n) return 0; - *newch = (unsigned char *)emalloc(HOWMANY + 1)); + if ((*newch = CAST(unsigned char *, emalloc(HOWMANY + 1))) == NULL) { + return 0; + } /* XXX: const castaway, via strchr */ z.next_in = (Bytef *)strchr((const char *)old + data_start, old[data_start]); - z.avail_in = n - data_start; + z.avail_in = CAST(uint32_t, (n - data_start)); z.next_out = *newch; z.avail_out = HOWMANY; z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; + /* LINTED bug in header macro */ rc = inflateInit2(&z, -15); if (rc != Z_OK) { file_error(ms, 0, "zlib: %s", z.msg); @@ -381,7 +387,8 @@ uncompressbuf(struct magic_set *ms, int fd, size_t met const unsigned char *old, unsigned char **newch, size_t n) { int fdin[2], fdout[2]; - int r; + ssize_t r; + pid_t pid; #ifdef BUILTIN_DECOMPRESS /* FIXME: This doesn't cope with bzip2 */ @@ -395,12 +402,12 @@ uncompressbuf(struct magic_set *ms, int fd, size_t met file_error(ms, errno, "cannot create pipe"); return NODATA; } - switch (fork()) { + switch (pid = fork()) { case 0: /* child */ (void) close(0); if (fd != -1) { (void) dup(fd); - (void) lseek(0, (off_t)0, SEEK_SET); + (void) FINFO_LSEEK_FUNC(0, (off_t)0, SEEK_SET); } else { (void) dup(fdin[0]); (void) close(fdin[0]); @@ -486,7 +493,7 @@ err: (void) close(fdin[1]); (void) close(fdout[0]); #ifdef WNOHANG - while (waitpid(-1, NULL, WNOHANG) != -1) + while (waitpid(pid, NULL, WNOHANG) != -1) continue; #else (void)wait(NULL);