]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-file-update.patch
- internal file update (for compatibility with *.mgc generated by file-4.14)
[packages/rpm.git] / rpm-file-update.patch
CommitLineData
1da879ec
JB
1--- rpm-4.4.1/file/src/file.h.orig 2005-01-03 00:11:30.000000000 +0100
2+++ rpm-4.4.1/file/src/file.h 2005-07-19 19:22:21.264100296 +0200
3@@ -27,7 +27,7 @@
4 */
5 /*
6 * file.h - definitions for file(1) program
7- * @(#)$Id$
8+ * @(#)$Id$
9 */
10
11 #ifndef __file_h__
12@@ -65,9 +65,9 @@
13 #define public
14
15 #ifndef HOWMANY
16-# define HOWMANY 65536 /* how much of the file to look at */
17+# define HOWMANY (256 * 1024) /* how much of the file to look at */
18 #endif
19-#define MAXMAGIS 4096 /* max entries in /etc/magic */
20+#define MAXMAGIS 8192 /* max entries in /etc/magic */
21 #define MAXDESC 64 /* max leng of text description */
22 #define MAXstring 32 /* max leng of "string" types */
23
24@@ -87,6 +87,7 @@
25 #define INDIR 1 /* if '>(...)' appears, */
26 #define UNSIGNED 2 /* comparison is unsigned */
27 #define OFFADD 4 /* if '>&' appears, */
28+#define INDIROFFADD 8 /* if '>&(' appears, */
29 /* Word 2 */
30 uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
31 uint8_t vallen; /* length of string value, if any */
32@@ -110,6 +111,7 @@
33 #define FILE_REGEX 17
34 #define FILE_BESTRING16 18
35 #define FILE_LESTRING16 19
36+#define FILE_SEARCH 20
37
38 #define FILE_FORMAT_NAME \
39 /* 0 */ "invalid 0", \
40@@ -121,7 +123,7 @@
41 /* 6 */ "date", \
42 /* 7 */ "beshort", \
43 /* 8 */ "belong", \
44-/* 9 */ "bedate" \
45+/* 9 */ "bedate", \
46 /* 10 */ "leshort", \
47 /* 11 */ "lelong", \
48 /* 12 */ "ledate", \
49@@ -131,7 +133,8 @@
50 /* 16 */ "leldate", \
51 /* 17 */ "regex", \
52 /* 18 */ "bestring16", \
53-/* 19 */ "lestring16",
54+/* 19 */ "lestring16", \
55+/* 20 */ "search",
56
57 #define FILE_FMT_NUM "cduxXi"
58 #define FILE_FMT_STR "s"
59@@ -156,7 +159,8 @@
60 /* 16 */ FILE_FMT_STR, \
61 /* 17 */ FILE_FMT_STR, \
62 /* 18 */ FILE_FMT_STR, \
63-/* 19 */ FILE_FMT_STR,
64+/* 19 */ FILE_FMT_STR, \
65+/* 20 */ FILE_FMT_STR,
66
67 /* Word 3 */
68 uint8_t in_op; /* operator for indirection */
69@@ -172,11 +176,12 @@
70 #define FILE_OPMULTIPLY 5
71 #define FILE_OPDIVIDE 6
72 #define FILE_OPMODULO 7
73-#define FILE_OPINVERSE 0x80
74+#define FILE_OPINVERSE 0x40
75+#define FILE_OPINDIRECT 0x80
76 /* Word 4 */
77 uint32_t offset; /* offset to magic number */
78 /* Word 5 */
79- uint32_t in_offset; /* offset from indirection */
80+ int32_t in_offset; /* offset from indirection */
81 /* Word 6 */
82 uint32_t mask; /* mask before comparison with value */
83 /* Word 7 */
84--- rpm-4.4.1/file/src/softmagic.c.orig 2005-01-26 04:39:56.000000000 +0100
85+++ rpm-4.4.1/file/src/softmagic.c 2005-07-19 18:50:47.923931752 +0200
86@@ -39,7 +39,7 @@
87
88
89 #ifndef lint
90-FILE_RCSID("@(#)$Id$")
91+FILE_RCSID("@(#)$Id$")
92 #endif /* lint */
93
94 private int match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
95@@ -47,7 +47,7 @@
96 /*@globals fileSystem @*/
97 /*@modifies ms, magic, fileSystem @*/;
98 private int mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
99- struct magic *m, size_t nbytes)
100+ struct magic *m, size_t nbytes, int i)
101 /*@globals fileSystem @*/
102 /*@modifies ms, p, m, fileSystem @*/;
103 private int mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
104@@ -128,15 +128,20 @@
105
106 for (magindex = 0; magindex < nmagic; magindex++) {
107 /* if main entry matches, print it... */
108- int flush = !mget(ms, &p, s, &magic[magindex], nbytes);
109- switch (mcheck(ms, &p, &magic[magindex])) {
110- case -1:
111- return -1;
112- case 0:
113- flush++;
114- /*@switchbreak@*/ break;
115- default:
116- /*@switchbreak@*/ break;
117+ int flush = !mget(ms, &p, s, &magic[magindex], nbytes,
118+ cont_level);
119+ if (flush) {
120+ if (magic[magindex].reln == '!') flush = 0;
121+ } else {
122+ switch (mcheck(ms, &p, &magic[magindex])) {
123+ case -1:
124+ return -1;
125+ case 0:
126+ flush++;
127+ /*@switchbreak@*/ break;
128+ default:
129+ /*@switchbreak@*/ break;
130+ }
131 }
132 if (flush) {
133 /*
134@@ -179,14 +184,18 @@
135 */
136 cont_level = magic[magindex].cont_level;
137 }
138+ oldoff = magic[magindex].offset;
139 if (magic[magindex].flag & OFFADD) {
140- oldoff=magic[magindex].offset;
141- magic[magindex].offset += ms->c.off[cont_level-1];
142+ magic[magindex].offset +=
143+ ms->c.off[cont_level-1];
144 }
145- if (!mget(ms, &p, s, &magic[magindex], nbytes))
146+
147+ flush = !mget(ms, &p, s, &magic[magindex], nbytes,
148+ cont_level);
149+ if (flush && magic[magindex].reln != '!')
150 goto done;
151
152- switch (mcheck(ms, &p, &magic[magindex])) {
153+ switch (flush ? 1 : mcheck(ms, &p, &magic[magindex])) {
154 case -1:
155 return -1;
156 case 0:
157@@ -222,9 +231,7 @@
158 return -1;
159 }
160 done:
161- if (magic[magindex].flag & OFFADD) {
162- magic[magindex].offset = oldoff;
163- }
164+ magic[magindex].offset = oldoff;
165 }
166 firstline = 0;
167 returnval = 1;
168@@ -288,10 +295,10 @@
169 case FILE_PSTRING:
170 case FILE_BESTRING16:
171 case FILE_LESTRING16:
172- if (m->reln == '=') {
173+ if (m->reln == '=' || m->reln == '!') {
174 if (file_printf(ms, m->desc, m->value.s) == -1)
175 return -1;
176- t = m->offset + strlen(m->value.s);
177+ t = m->offset + m->vallen;
178 }
179 else {
180 if (*m->value.s == '\0') {
181@@ -325,6 +332,11 @@
182 return -1;
183 t = m->offset + strlen(p->s);
184 break;
185+ case FILE_SEARCH:
186+ if (file_printf(ms, m->desc, m->value.s) == -1)
187+ return -1;
188+ t = m->offset + m->vallen;
189+ break;
190
191 default:
192 file_error(ms, 0, "invalid m->type (%d) in mprint()", m->type);
193@@ -344,7 +356,7 @@
194 switch (m->type) {
195 case FILE_BYTE:
196 if (m->mask)
197- switch (m->mask_op&0x7F) {
198+ switch (m->mask_op & 0x7F) {
199 case FILE_OPAND:
200 p->b &= m->mask;
201 /*@innerbreak@*/ break;
202@@ -375,7 +387,7 @@
203 return 1;
204 case FILE_SHORT:
205 if (m->mask)
206- switch (m->mask_op&0x7F) {
207+ switch (m->mask_op & 0x7F) {
208 case FILE_OPAND:
209 p->h &= m->mask;
210 /*@innerbreak@*/ break;
211@@ -408,7 +420,7 @@
212 case FILE_DATE:
213 case FILE_LDATE:
214 if (m->mask)
215- switch (m->mask_op&0x7F) {
216+ switch (m->mask_op & 0x7F) {
217 case FILE_OPAND:
218 p->l &= m->mask;
219 /*@innerbreak@*/ break;
220@@ -599,6 +611,7 @@
221 p->l = ~p->l;
222 return 1;
223 case FILE_REGEX:
224+ case FILE_SEARCH:
225 return 1;
226 default:
227 file_error(ms, 0, "invalid type %d in mconvert()", m->type);
228@@ -625,15 +638,17 @@
229 * offset is interpreted as last line to search,
230 * (starting at 1), not as bytes-from start-of-file
231 */
232- unsigned char *b, *last = NULL;
233+ char *b, *c, *last = NULL;
234 if ((p->buf = strdup((const char *)s)) == NULL) {
235 file_oomem(ms);
236 return -1;
237 }
238- for (b = (unsigned char *)p->buf; offset &&
239- (b = (unsigned char *)strchr((char *)b, '\n')) != NULL;
240- offset--, s++)
241+ for (b = p->buf; offset &&
242+ ((b = strchr(c = b, '\n')) || (b = strchr(c, '\r')));
243+ offset--, b++) {
244 last = b;
245+ if (b[0] == '\r' && b[1] == '\n') b++;
246+ }
247 if (last != NULL)
248 *last = '\0';
249 return 0;
250@@ -682,80 +697,77 @@
251
252 private int
253 mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
254- struct magic *m, size_t nbytes)
255+ struct magic *m, size_t nbytes, int cont_level)
256 {
257 uint32_t offset = m->offset;
258
259 if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes) == -1)
260 return -1;
261
262- /* Verify we have enough data to match magic type */
263- switch (m->type) {
264- case FILE_BYTE:
265- if (nbytes < (offset + 1)) /* should alway be true */
266- return 0;
267- break;
268-
269- case FILE_SHORT:
270- case FILE_BESHORT:
271- case FILE_LESHORT:
272- if (nbytes < (offset + 2))
273- return 0;
274- break;
275-
276- case FILE_LONG:
277- case FILE_BELONG:
278- case FILE_LELONG:
279- case FILE_DATE:
280- case FILE_BEDATE:
281- case FILE_LEDATE:
282- case FILE_LDATE:
283- case FILE_BELDATE:
284- case FILE_LELDATE:
285- if (nbytes < (offset + 4))
286- return 0;
287- break;
288-
289- case FILE_STRING:
290- case FILE_PSTRING:
291- if (nbytes < (offset + m->vallen))
292- return 0;
293- break;
294- }
295-
296 if ((ms->flags & MAGIC_DEBUG) != 0) {
297 mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
298 file_mdump(m);
299 }
300
301 if (m->flag & INDIR) {
302+ int off = m->in_offset;
303+ if (m->in_op & FILE_OPINDIRECT) {
304+ const union VALUETYPE *q =
305+ ((const union VALUETYPE *)(s + offset + off));
306+ switch (m->in_type) {
307+ case FILE_BYTE:
308+ off = q->b;
309+ break;
310+ case FILE_SHORT:
311+ off = q->h;
312+ break;
313+ case FILE_BESHORT:
314+ off = (short)((q->hs[0]<<8)|(q->hs[1]));
315+ break;
316+ case FILE_LESHORT:
317+ off = (short)((q->hs[1]<<8)|(q->hs[0]));
318+ break;
319+ case FILE_LONG:
320+ off = q->l;
321+ break;
322+ case FILE_BELONG:
323+ off = (int32_t)((q->hl[0]<<24)|(q->hl[1]<<16)|
324+ (q->hl[2]<<8)|(q->hl[3]));
325+ break;
326+ case FILE_LELONG:
327+ off = (int32_t)((q->hl[3]<<24)|(q->hl[2]<<16)|
328+ (q->hl[1]<<8)|(q->hl[0]));
329+ break;
330+ }
331+ }
332 switch (m->in_type) {
333 case FILE_BYTE:
334- if (m->in_offset) {
335- switch (m->in_op&0x7F) {
336+ if (nbytes < (offset + 1)) return 0;
337+ if (off) {
338+ switch (m->in_op & 0x3F) {
339 case FILE_OPAND:
340- offset = p->b & m->in_offset;
341+ offset = p->b & off;
342 /*@innerbreak@*/ break;
343 case FILE_OPOR:
344- offset = p->b | m->in_offset;
345+ offset = p->b | off;
346 /*@innerbreak@*/ break;
347 case FILE_OPXOR:
348- offset = p->b ^ m->in_offset;
349+ offset = p->b ^ off;
350 /*@innerbreak@*/ break;
351 case FILE_OPADD:
352- offset = p->b + m->in_offset;
353+ offset = p->b + off;
354 /*@innerbreak@*/ break;
355 case FILE_OPMINUS:
356- offset = p->b - m->in_offset;
357+ offset = p->b - off;
358 /*@innerbreak@*/ break;
359 case FILE_OPMULTIPLY:
360- offset = p->b * m->in_offset;
361+ offset = p->b * off;
362 /*@innerbreak@*/ break;
363 case FILE_OPDIVIDE:
364- offset = p->b / m->in_offset;
365+ offset = p->b / off;
366 /*@innerbreak@*/ break;
367 case FILE_OPMODULO:
368- offset = p->b % m->in_offset;
369+ offset = p->b % off;
370 /*@innerbreak@*/ break;
371 }
372 } else
373@@ -764,47 +776,49 @@
374 offset = ~offset;
375 break;
376 case FILE_BESHORT:
377- if (m->in_offset) {
378+ if (nbytes < (offset + 2))
379+ return 0;
380+ if (off) {
381 switch (m->in_op & 0x7F) {
382 case FILE_OPAND:
383 offset = (short)((p->hs[0]<<8)|
384 (p->hs[1])) &
385- m->in_offset;
386+ off;
387 /*@innerbreak@*/ break;
388 case FILE_OPOR:
389 offset = (short)((p->hs[0]<<8)|
390 (p->hs[1])) |
391- m->in_offset;
392+ off;
393 /*@innerbreak@*/ break;
394 case FILE_OPXOR:
395 offset = (short)((p->hs[0]<<8)|
396 (p->hs[1])) ^
397- m->in_offset;
398+ off;
399 /*@innerbreak@*/ break;
400 case FILE_OPADD:
401 offset = (short)((p->hs[0]<<8)|
402 (p->hs[1])) +
403- m->in_offset;
404+ off;
405 /*@innerbreak@*/ break;
406 case FILE_OPMINUS:
407 offset = (short)((p->hs[0]<<8)|
408 (p->hs[1])) -
409- m->in_offset;
410+ off;
411 /*@innerbreak@*/ break;
412 case FILE_OPMULTIPLY:
413 offset = (short)((p->hs[0]<<8)|
414 (p->hs[1])) *
415- m->in_offset;
416+ off;
417 /*@innerbreak@*/ break;
418 case FILE_OPDIVIDE:
419 offset = (short)((p->hs[0]<<8)|
420 (p->hs[1])) /
421- m->in_offset;
422+ off;
423 /*@innerbreak@*/ break;
424 case FILE_OPMODULO:
425 offset = (short)((p->hs[0]<<8)|
426 (p->hs[1])) %
427- m->in_offset;
428+ off;
429 /*@innerbreak@*/ break;
430 }
431 } else
432@@ -814,47 +828,49 @@
433 offset = ~offset;
434 break;
435 case FILE_LESHORT:
436- if (m->in_offset) {
437+ if (nbytes < (offset + 2))
438+ return 0;
439+ if (off) {
440 switch (m->in_op & 0x7F) {
441 case FILE_OPAND:
442 offset = (short)((p->hs[1]<<8)|
443 (p->hs[0])) &
444- m->in_offset;
445+ off;
446 /*@innerbreak@*/ break;
447 case FILE_OPOR:
448 offset = (short)((p->hs[1]<<8)|
449 (p->hs[0])) |
450- m->in_offset;
451+ off;
452 /*@innerbreak@*/ break;
453 case FILE_OPXOR:
454 offset = (short)((p->hs[1]<<8)|
455 (p->hs[0])) ^
456- m->in_offset;
457+ off;
458 /*@innerbreak@*/ break;
459 case FILE_OPADD:
460 offset = (short)((p->hs[1]<<8)|
461 (p->hs[0])) +
462- m->in_offset;
463+ off;
464 /*@innerbreak@*/ break;
465 case FILE_OPMINUS:
466 offset = (short)((p->hs[1]<<8)|
467 (p->hs[0])) -
468- m->in_offset;
469+ off;
470 /*@innerbreak@*/ break;
471 case FILE_OPMULTIPLY:
472 offset = (short)((p->hs[1]<<8)|
473 (p->hs[0])) *
474- m->in_offset;
475+ off;
476 /*@innerbreak@*/ break;
477 case FILE_OPDIVIDE:
478 offset = (short)((p->hs[1]<<8)|
479 (p->hs[0])) /
480- m->in_offset;
481+ off;
482 /*@innerbreak@*/ break;
483 case FILE_OPMODULO:
484 offset = (short)((p->hs[1]<<8)|
485 (p->hs[0])) %
486- m->in_offset;
487+ off;
488 /*@innerbreak@*/ break;
489 }
490 } else
491@@ -864,31 +880,33 @@
492 offset = ~offset;
493 break;
494 case FILE_SHORT:
495- if (m->in_offset) {
496+ if (nbytes < (offset + 2))
497+ return 0;
498+ if (off) {
499 switch (m->in_op & 0x7F) {
500 case FILE_OPAND:
501- offset = p->h & m->in_offset;
502+ offset = p->h & off;
503 /*@innerbreak@*/ break;
504 case FILE_OPOR:
505- offset = p->h | m->in_offset;
506+ offset = p->h | off;
507 /*@innerbreak@*/ break;
508 case FILE_OPXOR:
509- offset = p->h ^ m->in_offset;
510+ offset = p->h ^ off;
511 /*@innerbreak@*/ break;
512 case FILE_OPADD:
513- offset = p->h + m->in_offset;
514+ offset = p->h + off;
515 /*@innerbreak@*/ break;
516 case FILE_OPMINUS:
517- offset = p->h - m->in_offset;
518+ offset = p->h - off;
519 /*@innerbreak@*/ break;
520 case FILE_OPMULTIPLY:
521- offset = p->h * m->in_offset;
522+ offset = p->h * off;
523 /*@innerbreak@*/ break;
524 case FILE_OPDIVIDE:
525- offset = p->h / m->in_offset;
526+ offset = p->h / off;
527 /*@innerbreak@*/ break;
528 case FILE_OPMODULO:
529- offset = p->h % m->in_offset;
530+ offset = p->h % off;
531 /*@innerbreak@*/ break;
532 }
533 }
534@@ -898,63 +916,65 @@
535 offset = ~offset;
536 break;
537 case FILE_BELONG:
538- if (m->in_offset) {
539+ if (nbytes < (offset + 4))
540+ return 0;
541+ if (off) {
542 switch (m->in_op & 0x7F) {
543 case FILE_OPAND:
544 offset = (int32_t)((p->hl[0]<<24)|
545 (p->hl[1]<<16)|
546 (p->hl[2]<<8)|
547 (p->hl[3])) &
548- m->in_offset;
549+ off;
550 /*@innerbreak@*/ break;
551 case FILE_OPOR:
552 offset = (int32_t)((p->hl[0]<<24)|
553 (p->hl[1]<<16)|
554 (p->hl[2]<<8)|
555 (p->hl[3])) |
556- m->in_offset;
557+ off;
558 /*@innerbreak@*/ break;
559 case FILE_OPXOR:
560 offset = (int32_t)((p->hl[0]<<24)|
561 (p->hl[1]<<16)|
562 (p->hl[2]<<8)|
563 (p->hl[3])) ^
564- m->in_offset;
565+ off;
566 /*@innerbreak@*/ break;
567 case FILE_OPADD:
568 offset = (int32_t)((p->hl[0]<<24)|
569 (p->hl[1]<<16)|
570 (p->hl[2]<<8)|
571 (p->hl[3])) +
572- m->in_offset;
573+ off;
574 /*@innerbreak@*/ break;
575 case FILE_OPMINUS:
576 offset = (int32_t)((p->hl[0]<<24)|
577 (p->hl[1]<<16)|
578 (p->hl[2]<<8)|
579 (p->hl[3])) -
580- m->in_offset;
581+ off;
582 /*@innerbreak@*/ break;
583 case FILE_OPMULTIPLY:
584 offset = (int32_t)((p->hl[0]<<24)|
585 (p->hl[1]<<16)|
586 (p->hl[2]<<8)|
587 (p->hl[3])) *
588- m->in_offset;
589+ off;
590 /*@innerbreak@*/ break;
591 case FILE_OPDIVIDE:
592 offset = (int32_t)((p->hl[0]<<24)|
593 (p->hl[1]<<16)|
594 (p->hl[2]<<8)|
595 (p->hl[3])) /
596- m->in_offset;
597+ off;
598 /*@innerbreak@*/ break;
599 case FILE_OPMODULO:
600 offset = (int32_t)((p->hl[0]<<24)|
601 (p->hl[1]<<16)|
602 (p->hl[2]<<8)|
603 (p->hl[3])) %
604- m->in_offset;
605+ off;
606 /*@innerbreak@*/ break;
607 }
608 } else
609@@ -966,63 +986,65 @@
610 offset = ~offset;
611 break;
612 case FILE_LELONG:
613- if (m->in_offset) {
614+ if (nbytes < (offset + 4))
615+ return 0;
616+ if (off) {
617 switch (m->in_op & 0x7F) {
618 case FILE_OPAND:
619 offset = (int32_t)((p->hl[3]<<24)|
620 (p->hl[2]<<16)|
621 (p->hl[1]<<8)|
622 (p->hl[0])) &
623- m->in_offset;
624+ off;
625 /*@innerbreak@*/ break;
626 case FILE_OPOR:
627 offset = (int32_t)((p->hl[3]<<24)|
628 (p->hl[2]<<16)|
629 (p->hl[1]<<8)|
630 (p->hl[0])) |
631- m->in_offset;
632+ off;
633 /*@innerbreak@*/ break;
634 case FILE_OPXOR:
635 offset = (int32_t)((p->hl[3]<<24)|
636 (p->hl[2]<<16)|
637 (p->hl[1]<<8)|
638 (p->hl[0])) ^
639- m->in_offset;
640+ off;
641 /*@innerbreak@*/ break;
642 case FILE_OPADD:
643 offset = (int32_t)((p->hl[3]<<24)|
644 (p->hl[2]<<16)|
645 (p->hl[1]<<8)|
646 (p->hl[0])) +
647- m->in_offset;
648+ off;
649 /*@innerbreak@*/ break;
650 case FILE_OPMINUS:
651 offset = (int32_t)((p->hl[3]<<24)|
652 (p->hl[2]<<16)|
653 (p->hl[1]<<8)|
654 (p->hl[0])) -
655- m->in_offset;
656+ off;
657 /*@innerbreak@*/ break;
658 case FILE_OPMULTIPLY:
659 offset = (int32_t)((p->hl[3]<<24)|
660 (p->hl[2]<<16)|
661 (p->hl[1]<<8)|
662 (p->hl[0])) *
663- m->in_offset;
664+ off;
665 /*@innerbreak@*/ break;
666 case FILE_OPDIVIDE:
667 offset = (int32_t)((p->hl[3]<<24)|
668 (p->hl[2]<<16)|
669 (p->hl[1]<<8)|
670 (p->hl[0])) /
671- m->in_offset;
672+ off;
673 /*@innerbreak@*/ break;
674 case FILE_OPMODULO:
675 offset = (int32_t)((p->hl[3]<<24)|
676 (p->hl[2]<<16)|
677 (p->hl[1]<<8)|
678 (p->hl[0])) %
679- m->in_offset;
680+ off;
681 /*@innerbreak@*/ break;
682 }
683 } else
684@@ -1034,31 +1056,33 @@
685 offset = ~offset;
686 break;
687 case FILE_LONG:
688- if (m->in_offset) {
689+ if (nbytes < (offset + 4))
690+ return 0;
691+ if (off) {
692 switch (m->in_op & 0x7F) {
693 case FILE_OPAND:
694- offset = p->l & m->in_offset;
695+ offset = p->l & off;
696 /*@innerbreak@*/ break;
697 case FILE_OPOR:
698- offset = p->l | m->in_offset;
699+ offset = p->l | off;
700 /*@innerbreak@*/ break;
701 case FILE_OPXOR:
702- offset = p->l ^ m->in_offset;
703+ offset = p->l ^ off;
704 /*@innerbreak@*/ break;
705 case FILE_OPADD:
706- offset = p->l + m->in_offset;
707+ offset = p->l + off;
708 /*@innerbreak@*/ break;
709 case FILE_OPMINUS:
710- offset = p->l - m->in_offset;
711+ offset = p->l - off;
712 /*@innerbreak@*/ break;
713 case FILE_OPMULTIPLY:
714- offset = p->l * m->in_offset;
715+ offset = p->l * off;
716 /*@innerbreak@*/ break;
717 case FILE_OPDIVIDE:
718- offset = p->l / m->in_offset;
719+ offset = p->l / off;
720 /*@innerbreak@*/ break;
721 case FILE_OPMODULO:
722- offset = p->l % m->in_offset;
723+ offset = p->l % off;
724 /*@innerbreak@*/ break;
725 /* case TOOMANYSWITCHBLOCKS:
726 * ugh = p->eye % m->strain;
727@@ -1075,8 +1099,10 @@
728 break;
729 }
730
731+ if (m->flag & INDIROFFADD) offset += ms->c.off[cont_level-1];
732 if (mcopy(ms, p, m->type, 0, s, offset, nbytes) == -1)
733 return -1;
734+ m->offset = offset;
735
736 if ((ms->flags & MAGIC_DEBUG) != 0) {
737 mdebug(offset, (char *)(void *)p,
738@@ -1084,8 +1110,53 @@
739 file_mdump(m);
740 }
741 }
742+
743+ /* Verify we have enough data to match magic type */
744+ switch (m->type) {
745+ case FILE_BYTE:
746+ if (nbytes < (offset + 1)) /* should alway be true */
747+ return 0;
748+ break;
749+
750+ case FILE_SHORT:
751+ case FILE_BESHORT:
752+ case FILE_LESHORT:
753+ if (nbytes < (offset + 2))
754+ return 0;
755+ break;
756+
757+ case FILE_LONG:
758+ case FILE_BELONG:
759+ case FILE_LELONG:
760+ case FILE_DATE:
761+ case FILE_BEDATE:
762+ case FILE_LEDATE:
763+ case FILE_LDATE:
764+ case FILE_BELDATE:
765+ case FILE_LELDATE:
766+ if (nbytes < (offset + 4))
767+ return 0;
768+ break;
769+
770+ case FILE_STRING:
771+ case FILE_PSTRING:
772+ case FILE_SEARCH:
773+ if (nbytes < (offset + m->vallen))
774+ return 0;
775+ break;
776+ default: break;
777+ }
778+
779+ if (m->type == FILE_SEARCH) {
780+ p->buf = malloc(m->mask + m->vallen);
781+ if (p->buf == NULL) {
782+ file_error(ms, errno, "Cannot allocate search buffer");
783+ return 0;
784+ }
785+ (void)memcpy(p->buf, s + offset, m->mask + m->vallen);
786+ }
787 if (!mconvert(ms, p, m))
788- return 0;
789+ return 0;
790 return 1;
791 }
792
793@@ -1179,7 +1250,9 @@
794 regex_t rx;
795 char errmsg[512];
796
797- rc = regcomp(&rx, m->value.s, REG_EXTENDED|REG_NOSUB);
798+ rc = regcomp(&rx, m->value.s,
799+ REG_EXTENDED|REG_NOSUB|REG_NEWLINE|
800+ ((m->mask & STRING_IGNORE_LOWERCASE) ? REG_ICASE : 0));
801 if (rc) {
802 free(p->buf);
803 regerror(rc, &rx, errmsg, sizeof(errmsg));
804@@ -1194,6 +1267,31 @@
805 return !rc;
806 }
807 }
808+ case FILE_SEARCH:
809+ {
810+ /*
811+ * search for a string in a certain range
812+ */
813+ unsigned char *a = (unsigned char*)m->value.s;
814+ unsigned char *b = (unsigned char*)p->buf;
815+ int len = m->vallen;
816+ int range = 0;
817+ l = 0;
818+ v = 0;
819+ while (++range <= m->mask) {
820+ while (len-- > 0 && (v = *b++ - *a++) == 0)
821+ continue;
822+ if (!v) {
823+ m->offset += range-1;
824+ break;
825+ }
826+ len = m->vallen;
827+ a = (unsigned char*)m->value.s;
828+ b = (unsigned char*)p->buf + range;
829+ }
830+ free(p->buf);
831+ break;
832+ }
833 default:
834 file_error(ms, 0, "invalid type %d in mcheck()", m->type);
835 return -1;
This page took 0.133264 seconds and 4 git commands to generate.