Fix CID 1134837

This commit is contained in:
Anton Kochkov 2014-05-03 04:02:36 +04:00
parent ea57383d84
commit d56b4046de

View File

@ -3,7 +3,7 @@
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -13,7 +13,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -53,7 +53,7 @@
#endif
struct r_magic_entry {
struct r_magic *mp;
struct r_magic *mp;
ut32 cont_count;
ut32 max_count;
};
@ -204,7 +204,7 @@ static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *ml
}
mapped = rv;
if (magic == NULL) {
file_delmagic (magic, mapped, nmagic);
return -1;
@ -382,7 +382,7 @@ static size_t apprentice_r_magic_strength(const struct r_magic *m) {
return val? val: 1; /* ensure we only return 0 for FILE_DEFAULT */
}
/*
/*
* Sort callback for sorting entries by "strength" (basically length)
*/
static int apprentice_sort(const void *a, const void *b) {
@ -520,8 +520,10 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
/* load directory or file */
if (stat (fn, &st) == 0 && S_ISDIR (st.st_mode)) {
if (r_sandbox_enable (0) && !r_sandbox_check_path (fn))
if (r_sandbox_enable (0) && !r_sandbox_check_path (fn)) {
free (marray);
return -1;
}
dir = opendir (fn);
if (dir) {
while ((d = readdir (dir))) {
@ -585,7 +587,7 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
ms->line = marray[i].mp->lineno; /* XXX - Ugh! */
file_magwarn (ms, "level 0 \"default\" did not sort last");
}
break;
break;
}
}
@ -978,7 +980,7 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
"in_offset `%s' invalid", l);
l = t;
}
if (*l++ != ')' ||
if (*l++ != ')' ||
((m->in_op & FILE_OPINDIRECT) && *l++ != ')'))
if (ms->flags & R_MAGIC_CHECK)
file_magwarn(ms,
@ -1086,7 +1088,7 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
* anything if mask = 0 (unless you have a better idea)
*/
EATAB;
switch (*l) {
case '>':
case '<':
@ -1107,7 +1109,7 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
break;
default:
m->reln = '='; /* the default relation */
if (*l == 'x' && ((isascii((ut8)l[1]) &&
if (*l == 'x' && ((isascii((ut8)l[1]) &&
isspace ((ut8)l[1])) || !l[1])) {
m->reln = *l;
++l;
@ -1122,7 +1124,7 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
/*
* TODO finish this macro and start using it!
* #define offsetcheck {if (offset > HOWMANY-1)
* #define offsetcheck {if (offset > HOWMANY-1)
* magwarn("offset too big"); }
*/
@ -1183,7 +1185,7 @@ static int parse_mime(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp
file_error(ms, 0, "Current entry already has a MIME type: %s\n"
"Description: %s\nNew type: %s", m->mimetype, m->desc, l);
return -1;
}
}
EATAB;
for (i = 0;
@ -1275,7 +1277,7 @@ static int check_format_type(const char *ptr, int type) {
if (*ptr == '.')
ptr++;
while (isdigit ((ut8)*ptr)) ptr++;
switch (*ptr++) {
case 'e':
case 'E':
@ -1284,7 +1286,7 @@ static int check_format_type(const char *ptr, int type) {
case 'g':
case 'G':
return 0;
default:
return -1;
}
@ -1298,7 +1300,7 @@ static int check_format_type(const char *ptr, int type) {
while (isdigit ((ut8 )*ptr))
ptr++;
}
if (*ptr++=='s')
return 0;
return -1;
@ -1309,7 +1311,7 @@ static int check_format_type(const char *ptr, int type) {
/*NOTREACHED*/
return -1;
}
/*
* Check that the optional printf format in description matches
* the type of the magic.
@ -1329,7 +1331,7 @@ static int check_format(RMagic *ms, struct r_magic *m) {
if (m->type >= file_nformats) {
file_magwarn(ms, "Internal error inconsistency between "
"m->type and format strings");
"m->type and format strings");
return -1;
}
if (file_formats[m->type] == FILE_FMT_NONE) {
@ -1350,7 +1352,7 @@ static int check_format(RMagic *ms, struct r_magic *m) {
file_names[m->type], m->desc);
return -1;
}
for (; *ptr; ptr++) {
if (*ptr == '%') {
file_magwarn (ms,
@ -1363,9 +1365,9 @@ static int check_format(RMagic *ms, struct r_magic *m) {
return 0;
}
/*
* Read a numeric value from a pointer, into the value union of a magic
* pointer, according to the magic type. Update the string pointer to point
/*
* Read a numeric value from a pointer, into the value union of a magic
* pointer, according to the magic type. Update the string pointer to point
* just after the number read. Return 0 for success, non-zero for failure.
*/
static int getvalue(RMagic *ms, struct r_magic *m, const char **p, int action) {
@ -1589,7 +1591,7 @@ void file_showstr(FILE *fp, const char *s, size_t len) {
static void eatsize(const char **p) {
const char *l = *p;
if (LOWCASE (*l) == 'u')
if (LOWCASE (*l) == 'u')
l++;
switch (LOWCASE (*l)) {
@ -1734,7 +1736,7 @@ static int apprentice_compile(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp
goto beach;
}
if (write(fd, *magicp, (sizeof(struct r_magic) * *nmagicp))
if (write(fd, *magicp, (sizeof(struct r_magic) * *nmagicp))
!= (ssize_t)(sizeof(struct r_magic) * *nmagicp)) {
file_error(ms, errno, "error writing `%s'", dbname);
goto beach;
@ -1788,8 +1790,8 @@ static void byteswap(struct r_magic *magic, ut32 nmagic) {
*/
static ut16 swap2(ut16 sv) {
ut16 rv;
ut8 *s = (ut8 *)(void *)&sv;
ut8 *d = (ut8 *)(void *)&rv;
ut8 *s = (ut8 *)(void *)&sv;
ut8 *d = (ut8 *)(void *)&rv;
d[0] = s[1];
d[1] = s[0];
return rv;
@ -1800,8 +1802,8 @@ static ut16 swap2(ut16 sv) {
*/
static ut32 swap4(ut32 sv) {
ut32 rv;
ut8 *s = (ut8 *)(void *)&sv;
ut8 *d = (ut8 *)(void *)&rv;
ut8 *s = (ut8 *)(void *)&sv;
ut8 *d = (ut8 *)(void *)&rv;
d[0] = s[3];
d[1] = s[2];
d[2] = s[1];
@ -1814,8 +1816,8 @@ static ut32 swap4(ut32 sv) {
*/
static ut64 swap8(ut64 sv) {
ut64 rv;
ut8 *s = (ut8 *)(void *)&sv;
ut8 *d = (ut8 *)(void *)&rv;
ut8 *s = (ut8 *)(void *)&sv;
ut8 *d = (ut8 *)(void *)&rv;
#if 0
d[0] = s[3];
d[1] = s[2];