mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
MFV r299237: apply two upstream revisions to address upstream bug PR/540.
PR: 209211 MFC after: 2 weeks X-MFC: if there is no new file release
This commit is contained in:
commit
53021c7e30
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299238
|
@ -32,7 +32,7 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
FILE_RCSID("@(#)$File: softmagic.c,v 1.229 2016/03/21 23:04:40 christos Exp $")
|
FILE_RCSID("@(#)$File: softmagic.c,v 1.230 2016/04/18 15:10:34 christos Exp $")
|
||||||
#endif /* lint */
|
#endif /* lint */
|
||||||
|
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
@ -186,11 +186,11 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||||
((text && (m->str_flags & FLT) == STRING_BINTEST) ||
|
((text && (m->str_flags & FLT) == STRING_BINTEST) ||
|
||||||
(!text && (m->str_flags & FLT) == STRING_TEXTTEST))) ||
|
(!text && (m->str_flags & FLT) == STRING_TEXTTEST))) ||
|
||||||
(m->flag & mode) != mode) {
|
(m->flag & mode) != mode) {
|
||||||
|
flush:
|
||||||
/* Skip sub-tests */
|
/* Skip sub-tests */
|
||||||
while (magindex + 1 < nmagic &&
|
while (magindex < nmagic - 1 &&
|
||||||
magic[magindex + 1].cont_level != 0 &&
|
magic[magindex + 1].cont_level != 0)
|
||||||
++magindex)
|
magindex++;
|
||||||
continue;
|
|
||||||
continue; /* Skip to next top-level test*/
|
continue; /* Skip to next top-level test*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,10 +227,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||||
* main entry didn't match,
|
* main entry didn't match,
|
||||||
* flush its continuations
|
* flush its continuations
|
||||||
*/
|
*/
|
||||||
while (magindex < nmagic - 1 &&
|
goto flush;
|
||||||
magic[magindex + 1].cont_level != 0)
|
|
||||||
magindex++;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((e = handle_annotation(ms, m)) != 0) {
|
if ((e = handle_annotation(ms, m)) != 0) {
|
||||||
|
@ -255,8 +252,13 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||||
if (print && mprint(ms, m) == -1)
|
if (print && mprint(ms, m) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (moffset(ms, m, nbytes, &ms->c.li[cont_level].off) == -1)
|
switch (moffset(ms, m, nbytes, &ms->c.li[cont_level].off)) {
|
||||||
return -1;
|
case -1:
|
||||||
|
case 0:
|
||||||
|
goto flush;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* and any continuations that match */
|
/* and any continuations that match */
|
||||||
if (file_check_mem(ms, ++cont_level) == -1)
|
if (file_check_mem(ms, ++cont_level) == -1)
|
||||||
|
@ -362,9 +364,15 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||||
if (print && mprint(ms, m) == -1)
|
if (print && mprint(ms, m) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (moffset(ms, m, nbytes,
|
switch (moffset(ms, m, nbytes,
|
||||||
&ms->c.li[cont_level].off) == -1)
|
&ms->c.li[cont_level].off)) {
|
||||||
return -1;
|
case -1:
|
||||||
|
case 0:
|
||||||
|
flush = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (*m->desc)
|
if (*m->desc)
|
||||||
*need_separator = 1;
|
*need_separator = 1;
|
||||||
|
@ -813,9 +821,13 @@ moffset(struct magic_set *ms, struct magic *m, size_t nbytes, int32_t *op)
|
||||||
case FILE_DER:
|
case FILE_DER:
|
||||||
{
|
{
|
||||||
o = der_offs(ms, m, nbytes);
|
o = der_offs(ms, m, nbytes);
|
||||||
if (o == -1) {
|
if (o == -1 || (size_t)o > nbytes) {
|
||||||
file_error(ms, 0, "EOF computing DER offset");
|
if ((ms->flags & MAGIC_DEBUG) != 0) {
|
||||||
return -1;
|
(void)fprintf(stderr,
|
||||||
|
"Bad DER offset %d nbytes=%zu",
|
||||||
|
o, nbytes);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -825,12 +837,15 @@ moffset(struct magic_set *ms, struct magic *m, size_t nbytes, int32_t *op)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((size_t)o >= nbytes) {
|
if ((size_t)o > nbytes) {
|
||||||
file_error(ms, 0, "Offset out of range");
|
#if 0
|
||||||
|
file_error(ms, 0, "Offset out of range %zu > %zu",
|
||||||
|
(size_t)o, nbytes);
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*op = o;
|
*op = o;
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private uint32_t
|
private uint32_t
|
||||||
|
@ -2107,8 +2122,13 @@ magiccheck(struct magic_set *ms, struct magic *m)
|
||||||
return 1;
|
return 1;
|
||||||
case FILE_DER:
|
case FILE_DER:
|
||||||
matched = der_cmp(ms, m);
|
matched = der_cmp(ms, m);
|
||||||
if (matched == -1)
|
if (matched == -1) {
|
||||||
file_error(ms, 0, "EOF comparing DER entries");
|
if ((ms->flags & MAGIC_DEBUG) != 0) {
|
||||||
|
(void) fprintf(stderr,
|
||||||
|
"EOF comparing DER entries");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return matched;
|
return matched;
|
||||||
default:
|
default:
|
||||||
file_magerror(ms, "invalid type %d in magiccheck()", m->type);
|
file_magerror(ms, "invalid type %d in magiccheck()", m->type);
|
||||||
|
|
Loading…
Reference in a new issue