cvs commit: apachen/src/modules/standard mod_mime_magic.c
dgaudet 97/12/19 15:53:02 Modified:src CHANGES src/modules/standard mod_mime_magic.c Log: - fix an off-by-1 on read() which I think I introduced in an earlier cleanup - fix case where m-desc[] may be left unterminated - note some code which is not multithread safe Reviewed by: Jim Jagielski, Marc Slemko Revision ChangesPath 1.532 +3 -0 apachen/src/CHANGES Index: CHANGES === RCS file: /export/home/cvs/apachen/src/CHANGES,v retrieving revision 1.531 retrieving revision 1.532 diff -u -r1.531 -r1.532 --- CHANGES 1997/12/19 18:24:50 1.531 +++ CHANGES 1997/12/19 23:52:58 1.532 @@ -1,5 +1,8 @@ Changes with Apache 1.3b4 + *) Fix an off-by-1, and an unterminated string error in + mod_mime_magic. [Dean Gaudet] + *) Fix a potential SEGV problem in mod_negotiation when dealing with type-maps. [Dean Gaudet] 1.21 +8 -8 apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c === RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- mod_mime_magic.c 1997/11/16 01:52:23 1.20 +++ mod_mime_magic.c 1997/12/19 23:53:01 1.21 @@ -881,7 +881,7 @@ /* * try looking at the first HOWMANY bytes */ -if ((nbytes = read(fd, (char *) buf, sizeof(buf))) == -1) { +if ((nbytes = read(fd, (char *) buf, sizeof(buf) - 1)) == -1) { aplog_error(APLOG_MARK, APLOG_ERR, r-server, MODNAME : read failed: %s, r-filename); return HTTP_INTERNAL_SERVER_ERROR; @@ -1086,7 +1086,6 @@ */ static int parse(server_rec *serv, pool *p, char *l, int lineno) { -int i = 0; struct magic *m; char *t, *s; magic_server_config_rec *conf = (magic_server_config_rec *) @@ -1297,14 +1296,13 @@ } else m-nospflag = 0; -while ((m-desc[i++] = *l++) != '\0' i MAXDESC) - /* NULLBODY */ ; +strncpy(m-desc, l, sizeof(m-desc) - 1); +m-desc[sizeof(m-desc) - 1] = '\0'; #if MIME_MAGIC_DEBUG aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, serv, MODNAME : parse line=%d m=%x next=%x cont=%d desc=%s, - lineno, m, m-next, m-cont_level, - m-desc ? m-desc : NULL); + lineno, m, m-next, m-cont_level, m-desc); #endif /* MIME_MAGIC_DEBUG */ return 0; @@ -1650,7 +1648,7 @@ MODNAME : line=%d mc=%x mc-next=%x cont=%d desc=%s, m_cont-lineno, m_cont, m_cont-next, m_cont-cont_level, - m_cont-desc ? m_cont-desc : NULL); + m_cont-desc); #endif /* * this trick allows us to keep *m in sync when the continue @@ -1779,6 +1777,7 @@ case DATE: case BEDATE: case LEDATE: + /* XXX: not multithread safe */ pp = ctime((time_t *) p-l); if ((rt = strchr(pp, '\n')) != NULL) *rt = '\0'; @@ -1842,10 +1841,10 @@ struct magic *m, int nbytes) { long offset = m-offset; + if (offset + sizeof(union VALUETYPE) nbytes) return 0; - memcpy(p, s + offset, sizeof(union VALUETYPE)); if (!mconvert(r, p, m)) @@ -2066,6 +2065,7 @@ s = (unsigned char *) memcpy(nbuf, buf, small_nbytes); s[small_nbytes] = '\0'; has_escapes = (memchr(s, '\033', small_nbytes) != NULL); +/* XXX: not multithread safe */ while ((token = strtok((char *) s, \t\n\r\f)) != NULL) { s = NULL; /* make strtok() keep on tokin' */ for (p = names; p names + NNAMES; p++) {
cvs commit: apachen/src/modules/standard mod_mime_magic.c
marc97/11/15 17:52:24 Modified:src/modules/standard mod_mime_magic.c Log: Add typecast to removing a compiler warning on systems that consider mode_t and %o different. Reviewed by: Roy T. Fielding, Jim Jagielski, Dirk-Willem van Gulik Revision ChangesPath 1.20 +1 -1 apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c === RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- mod_mime_magic.c 1997/10/30 19:20:51 1.19 +++ mod_mime_magic.c 1997/11/16 01:52:23 1.20 @@ -1530,7 +1530,7 @@ break; default: aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, r-server, - MODNAME : invalid mode 0%o., sb-st_mode); + MODNAME : invalid mode 0%o., (unsigned int)sb-st_mode); return HTTP_INTERNAL_SERVER_ERROR; }
cvs commit: apachen/src/modules/standard mod_mime_magic.c
dgaudet 97/10/30 11:20:52 Modified:src CHANGES src/modules/standard mod_mime_magic.c Log: Bug Fixes: - gzip -cdq requires at least 4k of a partial gzipped file, we were sending it only 1k, and it wouldn't produce any output. But raising HOWMANY to 4k has implications on the performance of the (lame) ascmagic() code. So ascmagic() cheats and only looks at 1k (the previous HOWMANY setting) - use spawn_child() interface to avoid a resource leak (zombie child); I don't think even worked on WIN32 before, but it might now... I special case and use spawnvp() on WIN32. - use pfopen()/popenf() to avoid resource leaks Cleanups: - no need to test return from palloc since it never returns NULL - ensure all log messages include the module name - Some cases were assuming that aplog_error was a never returning function. Deal gracefully by propagating an error code back up the call chain. - remove some useless code in fsmagic() -- we don't use lstat(), we use stat() so the only possibility where we'll get S_IFLNK is if it's a broken symlink. - for various errors just DECLINE rather than cause the phase to abort early (a lesson we're learning from all the M_PUT changes we've had recently) PR: 1205 Reviewed by: Jim Jagielski, Martin Kraemer Revision ChangesPath 1.482 +5 -0 apachen/src/CHANGES Index: CHANGES === RCS file: /export/home/cvs/apachen/src/CHANGES,v retrieving revision 1.481 retrieving revision 1.482 diff -u -r1.481 -r1.482 --- CHANGES 1997/10/30 19:17:54 1.481 +++ CHANGES 1997/10/30 19:20:48 1.482 @@ -1,5 +1,10 @@ Changes with Apache 1.3b3 + *) Various mod_mime_magic bug fixes and cleanups: Uncompression + should work, it should work on WIN32, and a few resource + leaks and abort conditions are fixed. + [Dean Gaudet] PR#1205 + *) PORT: On AIX 1.x files can't be named '@', fix the proxy cache to use '%' instead of '@' in its encodings. [David Schuler [EMAIL PROTECTED]] PR#1317 1.19 +179 -206 apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c === RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- mod_mime_magic.c 1997/10/26 21:41:11 1.18 +++ mod_mime_magic.c 1997/10/30 19:20:51 1.19 @@ -144,7 +144,10 @@ #define MAXMIMESTRING256 -#define HOWMANY 1024 /* big enough to recognize most WWW files */ +/* HOWMANY must be at least 4096 to make gzip -dcq work */ +#define HOWMANY 4096 +/* SMALL_HOWMANY limits how much work we do to figure out text files */ +#define SMALL_HOWMANY 1024 #define MAXDESC50/* max leng of text description */ #define MAXstring 64 /* max leng of string types */ @@ -504,8 +507,8 @@ { magic_server_config_rec *base = (magic_server_config_rec *) basev; magic_server_config_rec *add = (magic_server_config_rec *) addv; -magic_server_config_rec *new -= (magic_server_config_rec *) palloc(p, sizeof(magic_server_config_rec)); +magic_server_config_rec *new = (magic_server_config_rec *) + palloc(p, sizeof(magic_server_config_rec)); new-magicfile = add-magicfile ? add-magicfile : base-magicfile; if (add-magic add-last) { @@ -565,12 +568,6 @@ magic_req_rec *req_dat = (magic_req_rec *) palloc(r-pool, sizeof(magic_req_rec)); -if (!req_dat) { - aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, r-server, - %s: memory allocation failure in magic_set_config(), - MODNAME); - return NULL; -} req_dat-head = req_dat-tail = (magic_rsl *) NULL; set_module_config(r-request_config, mime_magic_module, req_dat); return req_dat; @@ -587,8 +584,7 @@ /* make sure we have a list to put it in */ if (!req_dat) { aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, r-server, - %s: request config should not be NULL, - MODNAME); + MODNAME : request config should not be NULL); if (!(req_dat = magic_set_config(r))) { /* failure */ return -1; @@ -596,13 +592,7 @@ } /* allocate the list entry */ -if (!(rsl = (magic_rsl *) palloc(r-pool, sizeof(magic_rsl { - aplog_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, r-server, - %s: memory allocation failure in magic_rsl_add(), - MODNAME); - /* failure */ - return -1; -
cvs commit: apachen/src/modules/standard mod_mime_magic.c
dgaudet 97/10/26 13:41:13 Modified:src/modules/standard mod_mime_magic.c Log: The indentation was all whacky and there were various bits not in our coding style. Fix it up. (There's no code changes in this rev.) Revision ChangesPath 1.18 +1192 -1204apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c === RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- mod_mime_magic.c 1997/10/22 20:30:25 1.17 +++ mod_mime_magic.c 1997/10/26 21:41:11 1.18 @@ -144,26 +144,26 @@ #define MAXMIMESTRING256 -#define HOWMANY 1024/* big enough to recognize most WWW files */ -#define MAXDESC50 /* max leng of text description */ -#define MAXstring 64/* max leng of string types */ +#define HOWMANY 1024 /* big enough to recognize most WWW files */ +#define MAXDESC50/* max leng of text description */ +#define MAXstring 64 /* max leng of string types */ struct magic { -struct magic *next; /* link to next entry */ -int lineno; /* line number from magic file */ +struct magic *next; /* link to next entry */ +int lineno; /* line number from magic file */ short flag; -#define INDIR1 /* if '(...)' appears, */ -#defineUNSIGNED 2 /* comparison is unsigned */ -short cont_level; /* level of */ +#define INDIR1 /* if '(...)' appears, */ +#defineUNSIGNED 2/* comparison is unsigned */ +short cont_level;/* level of */ struct { -char type; /* byte short long */ -long offset;/* offset from indirection */ -} in; -long offset;/* offset to magic number */ -unsigned char reln; /* relation (0=eq, ''=gt, etc) */ -char type; /* int, short, long or string. */ -char vallen;/* length of string value, if any */ + char type; /* byte short long */ + long offset;/* offset from indirection */ +} in; +long offset; /* offset to magic number */ +unsigned char reln; /* relation (0=eq, ''=gt, etc) */ +char type; /* int, short, long or string. */ +char vallen; /* length of string value, if any */ #define BYTE1 #define SHORT2 #define LONG4 @@ -176,18 +176,18 @@ #define LELONG11 #define LEDATE12 union VALUETYPE { -unsigned char b; -unsigned short h; -unsigned long l; -char s[MAXstring]; -unsigned char hs[2];/* 2 bytes of a fixed-endian short */ -unsigned char hl[4];/* 2 bytes of a fixed-endian long */ -} value;/* either number or string */ -unsigned long mask; /* mask before comparison with value */ -char nospflag; /* supress space character */ + unsigned char b; + unsigned short h; + unsigned long l; + char s[MAXstring]; + unsigned char hs[2];/* 2 bytes of a fixed-endian short */ + unsigned char hl[4];/* 2 bytes of a fixed-endian long */ +} value; /* either number or string */ +unsigned long mask; /* mask before comparison with value */ +char nospflag; /* supress space character */ /* NOTE: this string is suspected of overrunning - find it! */ -char desc[MAXDESC]; /* description */ +char desc[MAXDESC]; /* description */ }; /* @@ -212,37 +212,34 @@ union record { char charptr[RECORDSIZE]; struct header { -char name[NAMSIZ]; -char mode[8]; -char uid[8]; -char gid[8]; -char size[12]; -char mtime[12]; -char chksum[8]; -char linkflag; -char linkname[NAMSIZ]; -char magic[8]; -char uname[TUNMLEN]; -char gname[TGNMLEN]; -char devmajor[8]; -char devminor[8]; -} header; + char name[NAMSIZ]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char chksum[8]; + char linkflag; + char linkname[NAMSIZ]; + char magic[8]; + char uname[TUNMLEN]; + char gname[TGNMLEN]; + char devmajor[8]; + char devminor[8]; +} header; }; /* The magic field is filled with this if uname and gname are valid. */ -#defineTMAGICustar/* 7 chars and a null
cvs commit: apachen/src/modules/standard mod_mime_magic.c
brian 97/08/22 14:55:41 Modified:src/modules/standard mod_mime_magic.c Log: Typo! Revision ChangesPath 1.13 +1 -1 apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c === RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- mod_mime_magic.c 1997/08/20 01:24:40 1.12 +++ mod_mime_magic.c 1997/08/22 21:55:37 1.13 @@ -2547,6 +2547,6 @@ NULL, /* logger */ NULL, /* header parser */ NULL, /* child_init */ - NULL /* child_exit */ + NULL, /* child_exit */ NULL /* post read-request */ };
cvs commit: apachen/src/modules/standard mod_mime_magic.c
dgaudet 97/08/19 18:24:41 Modified:src/modules/standard mod_mime_magic.c Log: remove unreachable code Revision ChangesPath 1.12 +1 -2 apachen/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c === RCS file: /export/home/cvs/apachen/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- mod_mime_magic.c 1997/08/18 13:12:16 1.11 +++ mod_mime_magic.c 1997/08/20 01:24:40 1.12 @@ -1581,9 +1581,8 @@ /* At MIME-typing time we want to follow symlinks */ /* So just handle it. */ magic_process(r); -return 1; } -return 1; + return 1; #endif #ifdefS_IFSOCK #ifndef __COHERENT__