summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2020-06-07 21:58:01 +0000
committerChristos Zoulas <christos@zoulas.com>2020-06-07 21:58:01 +0000
commitf9b78a2fcf6988f43838806e76800550f1d0d748 (patch)
tree440b6d229eead1b95a6862f9fe18a1434a03385a
parent481c3fe31dae934e4a92098fcafdd02032a4016d (diff)
downloadfile-git-f9b78a2fcf6988f43838806e76800550f1d0d748.tar.gz
Fix indirect offsets.
-rw-r--r--src/file.h6
-rw-r--r--src/softmagic.c18
2 files changed, 14 insertions, 10 deletions
diff --git a/src/file.h b/src/file.h
index 6e9a9063..a1791eab 100644
--- a/src/file.h
+++ b/src/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.218 2020/06/02 10:17:46 christos Exp $
+ * @(#)$File: file.h,v 1.219 2020/06/07 21:58:01 christos Exp $
*/
#ifndef __file_h__
@@ -423,9 +423,9 @@ struct magic_set {
size_t blen; /* Length of buffer */
char *pbuf; /* Printable buffer */
} o;
- uint32_t offset; /* a copy of m->offset while we */
+ int32_t offset; /* a copy of m->offset while we */
/* are working on the magic entry */
- uint32_t eoffset; /* offset from end of file */
+ int32_t eoffset; /* offset from end of file */
int error;
int flags; /* Control magic tests. */
int event_flags; /* Note things that happened. */
diff --git a/src/softmagic.c b/src/softmagic.c
index 23b7251c..95061e56 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.298 2020/06/07 20:12:55 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.299 2020/06/07 21:58:01 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -1510,7 +1510,9 @@ private int
msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb,
const struct buffer *b, size_t o, unsigned int cont_level)
{
+ int32_t offset;
if (m->flag & OFFNEGATIVE) {
+ offset = -m->offset;
if (cont_level > 0) {
if (m->flag & (OFFADD|INDIROFFADD))
goto normal;
@@ -1533,21 +1535,23 @@ msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb,
buffer_init(bb, -1, NULL, b->ebuf, b->elen);
ms->eoffset = ms->offset = CAST(int32_t, b->elen - m->offset);
} else {
+ offset = m->offset;
if (cont_level == 0) {
normal:
// XXX: Pass real fd, then who frees bb?
buffer_init(bb, -1, NULL, b->fbuf, b->flen);
- ms->offset = m->offset;
+ ms->offset = offset;
ms->eoffset = 0;
} else {
- ms->offset = ms->eoffset + m->offset;
+ ms->offset = ms->eoffset + offset;
}
}
if ((ms->flags & MAGIC_DEBUG) != 0) {
- fprintf(stderr, "bb=[%p,%" SIZE_T_FORMAT "u], %d [b=%p,%"
- SIZE_T_FORMAT "u], [o=%#x, c=%d]\n",
- bb->fbuf, bb->flen, ms->offset, b->fbuf, b->flen,
- m->offset, cont_level);
+ fprintf(stderr, "bb=[%p,%" SIZE_T_FORMAT "u,%"
+ SIZE_T_FORMAT "u], %d [b=%p,%"
+ SIZE_T_FORMAT "u,%" SIZE_T_FORMAT "u], [o=%#x, c=%d]\n",
+ bb->fbuf, bb->flen, bb->elen, ms->offset, b->fbuf,
+ b->flen, b->elen, offset, cont_level);
}
return 0;
}