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
6 * file.h - definitions for file(1) program
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 */
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 */
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, */
30 uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
31 uint8_t vallen; /* length of string value, if any */
34 #define FILE_BESTRING16 18
35 #define FILE_LESTRING16 19
36 +#define FILE_SEARCH 20
38 #define FILE_FORMAT_NAME \
39 /* 0 */ "invalid 0", \
52 /* 18 */ "bestring16", \
53 -/* 19 */ "lestring16",
54 +/* 19 */ "lestring16", \
57 #define FILE_FMT_NUM "cduxXi"
58 #define FILE_FMT_STR "s"
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,
68 uint8_t in_op; /* operator for indirection */
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
77 uint32_t offset; /* offset to magic number */
79 - uint32_t in_offset; /* offset from indirection */
80 + int32_t in_offset; /* offset from indirection */
82 uint32_t mask; /* mask before comparison with value */
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
90 -FILE_RCSID("@(#)$Id$")
91 +FILE_RCSID("@(#)$Id$")
94 private int match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
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 @@
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])) {
114 - /*@switchbreak@*/ break;
116 - /*@switchbreak@*/ break;
117 + int flush = !mget(ms, &p, s, &magic[magindex], nbytes,
120 + if (magic[magindex].reln == '!') flush = 0;
122 + switch (mcheck(ms, &p, &magic[magindex])) {
127 + /*@switchbreak@*/ break;
129 + /*@switchbreak@*/ break;
134 @@ -179,14 +184,18 @@
136 cont_level = magic[magindex].cont_level;
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];
145 - if (!mget(ms, &p, s, &magic[magindex], nbytes))
147 + flush = !mget(ms, &p, s, &magic[magindex], nbytes,
149 + if (flush && magic[magindex].reln != '!')
152 - switch (mcheck(ms, &p, &magic[magindex])) {
153 + switch (flush ? 1 : mcheck(ms, &p, &magic[magindex])) {
161 - if (magic[magindex].flag & OFFADD) {
162 - magic[magindex].offset = oldoff;
164 + magic[magindex].offset = oldoff;
168 @@ -288,10 +295,10 @@
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)
176 - t = m->offset + strlen(m->value.s);
177 + t = m->offset + m->vallen;
180 if (*m->value.s == '\0') {
183 t = m->offset + strlen(p->s);
186 + if (file_printf(ms, m->desc, m->value.s) == -1)
188 + t = m->offset + m->vallen;
192 file_error(ms, 0, "invalid m->type (%d) in mprint()", m->type);
197 - switch (m->mask_op&0x7F) {
198 + switch (m->mask_op & 0x7F) {
201 /*@innerbreak@*/ break;
206 - switch (m->mask_op&0x7F) {
207 + switch (m->mask_op & 0x7F) {
210 /*@innerbreak@*/ break;
215 - switch (m->mask_op&0x7F) {
216 + switch (m->mask_op & 0x7F) {
219 /*@innerbreak@*/ break;
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
232 - unsigned char *b, *last = NULL;
233 + char *b, *c, *last = NULL;
234 if ((p->buf = strdup((const char *)s)) == NULL) {
238 - for (b = (unsigned char *)p->buf; offset &&
239 - (b = (unsigned char *)strchr((char *)b, '\n')) != NULL;
241 + for (b = p->buf; offset &&
242 + ((b = strchr(c = b, '\n')) || (b = strchr(c, '\r')));
245 + if (b[0] == '\r' && b[1] == '\n') b++;
250 @@ -682,80 +697,77 @@
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)
257 uint32_t offset = m->offset;
259 if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes) == -1)
262 - /* Verify we have enough data to match magic type */
265 - if (nbytes < (offset + 1)) /* should alway be true */
272 - if (nbytes < (offset + 2))
285 - if (nbytes < (offset + 4))
291 - if (nbytes < (offset + m->vallen))
296 if ((ms->flags & MAGIC_DEBUG) != 0) {
297 mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
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) {
314 + off = (short)((q->hs[0]<<8)|(q->hs[1]));
317 + off = (short)((q->hs[1]<<8)|(q->hs[0]));
323 + off = (int32_t)((q->hl[0]<<24)|(q->hl[1]<<16)|
324 + (q->hl[2]<<8)|(q->hl[3]));
327 + off = (int32_t)((q->hl[3]<<24)|(q->hl[2]<<16)|
328 + (q->hl[1]<<8)|(q->hl[0]));
332 switch (m->in_type) {
334 - if (m->in_offset) {
335 - switch (m->in_op&0x7F) {
336 + if (nbytes < (offset + 1)) return 0;
338 + switch (m->in_op & 0x3F) {
340 - offset = p->b & m->in_offset;
341 + offset = p->b & off;
342 /*@innerbreak@*/ break;
344 - offset = p->b | m->in_offset;
345 + offset = p->b | off;
346 /*@innerbreak@*/ break;
348 - offset = p->b ^ m->in_offset;
349 + offset = p->b ^ off;
350 /*@innerbreak@*/ break;
352 - offset = p->b + m->in_offset;
353 + offset = p->b + off;
354 /*@innerbreak@*/ break;
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;
364 - offset = p->b / m->in_offset;
365 + offset = p->b / off;
366 /*@innerbreak@*/ break;
368 - offset = p->b % m->in_offset;
369 + offset = p->b % off;
370 /*@innerbreak@*/ break;
373 @@ -764,47 +776,49 @@
377 - if (m->in_offset) {
378 + if (nbytes < (offset + 2))
381 switch (m->in_op & 0x7F) {
383 offset = (short)((p->hs[0]<<8)|
387 /*@innerbreak@*/ break;
389 offset = (short)((p->hs[0]<<8)|
393 /*@innerbreak@*/ break;
395 offset = (short)((p->hs[0]<<8)|
399 /*@innerbreak@*/ break;
401 offset = (short)((p->hs[0]<<8)|
405 /*@innerbreak@*/ break;
407 offset = (short)((p->hs[0]<<8)|
411 /*@innerbreak@*/ break;
412 case FILE_OPMULTIPLY:
413 offset = (short)((p->hs[0]<<8)|
417 /*@innerbreak@*/ break;
419 offset = (short)((p->hs[0]<<8)|
423 /*@innerbreak@*/ break;
425 offset = (short)((p->hs[0]<<8)|
429 /*@innerbreak@*/ break;
432 @@ -814,47 +828,49 @@
436 - if (m->in_offset) {
437 + if (nbytes < (offset + 2))
440 switch (m->in_op & 0x7F) {
442 offset = (short)((p->hs[1]<<8)|
446 /*@innerbreak@*/ break;
448 offset = (short)((p->hs[1]<<8)|
452 /*@innerbreak@*/ break;
454 offset = (short)((p->hs[1]<<8)|
458 /*@innerbreak@*/ break;
460 offset = (short)((p->hs[1]<<8)|
464 /*@innerbreak@*/ break;
466 offset = (short)((p->hs[1]<<8)|
470 /*@innerbreak@*/ break;
471 case FILE_OPMULTIPLY:
472 offset = (short)((p->hs[1]<<8)|
476 /*@innerbreak@*/ break;
478 offset = (short)((p->hs[1]<<8)|
482 /*@innerbreak@*/ break;
484 offset = (short)((p->hs[1]<<8)|
488 /*@innerbreak@*/ break;
491 @@ -864,31 +880,33 @@
495 - if (m->in_offset) {
496 + if (nbytes < (offset + 2))
499 switch (m->in_op & 0x7F) {
501 - offset = p->h & m->in_offset;
502 + offset = p->h & off;
503 /*@innerbreak@*/ break;
505 - offset = p->h | m->in_offset;
506 + offset = p->h | off;
507 /*@innerbreak@*/ break;
509 - offset = p->h ^ m->in_offset;
510 + offset = p->h ^ off;
511 /*@innerbreak@*/ break;
513 - offset = p->h + m->in_offset;
514 + offset = p->h + off;
515 /*@innerbreak@*/ break;
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;
525 - offset = p->h / m->in_offset;
526 + offset = p->h / off;
527 /*@innerbreak@*/ break;
529 - offset = p->h % m->in_offset;
530 + offset = p->h % off;
531 /*@innerbreak@*/ break;
534 @@ -898,63 +916,65 @@
538 - if (m->in_offset) {
539 + if (nbytes < (offset + 4))
542 switch (m->in_op & 0x7F) {
544 offset = (int32_t)((p->hl[0]<<24)|
550 /*@innerbreak@*/ break;
552 offset = (int32_t)((p->hl[0]<<24)|
558 /*@innerbreak@*/ break;
560 offset = (int32_t)((p->hl[0]<<24)|
566 /*@innerbreak@*/ break;
568 offset = (int32_t)((p->hl[0]<<24)|
574 /*@innerbreak@*/ break;
576 offset = (int32_t)((p->hl[0]<<24)|
582 /*@innerbreak@*/ break;
583 case FILE_OPMULTIPLY:
584 offset = (int32_t)((p->hl[0]<<24)|
590 /*@innerbreak@*/ break;
592 offset = (int32_t)((p->hl[0]<<24)|
598 /*@innerbreak@*/ break;
600 offset = (int32_t)((p->hl[0]<<24)|
606 /*@innerbreak@*/ break;
609 @@ -966,63 +986,65 @@
613 - if (m->in_offset) {
614 + if (nbytes < (offset + 4))
617 switch (m->in_op & 0x7F) {
619 offset = (int32_t)((p->hl[3]<<24)|
625 /*@innerbreak@*/ break;
627 offset = (int32_t)((p->hl[3]<<24)|
633 /*@innerbreak@*/ break;
635 offset = (int32_t)((p->hl[3]<<24)|
641 /*@innerbreak@*/ break;
643 offset = (int32_t)((p->hl[3]<<24)|
649 /*@innerbreak@*/ break;
651 offset = (int32_t)((p->hl[3]<<24)|
657 /*@innerbreak@*/ break;
658 case FILE_OPMULTIPLY:
659 offset = (int32_t)((p->hl[3]<<24)|
665 /*@innerbreak@*/ break;
667 offset = (int32_t)((p->hl[3]<<24)|
673 /*@innerbreak@*/ break;
675 offset = (int32_t)((p->hl[3]<<24)|
681 /*@innerbreak@*/ break;
684 @@ -1034,31 +1056,33 @@
688 - if (m->in_offset) {
689 + if (nbytes < (offset + 4))
692 switch (m->in_op & 0x7F) {
694 - offset = p->l & m->in_offset;
695 + offset = p->l & off;
696 /*@innerbreak@*/ break;
698 - offset = p->l | m->in_offset;
699 + offset = p->l | off;
700 /*@innerbreak@*/ break;
702 - offset = p->l ^ m->in_offset;
703 + offset = p->l ^ off;
704 /*@innerbreak@*/ break;
706 - offset = p->l + m->in_offset;
707 + offset = p->l + off;
708 /*@innerbreak@*/ break;
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;
718 - offset = p->l / m->in_offset;
719 + offset = p->l / off;
720 /*@innerbreak@*/ break;
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 @@
731 + if (m->flag & INDIROFFADD) offset += ms->c.off[cont_level-1];
732 if (mcopy(ms, p, m->type, 0, s, offset, nbytes) == -1)
734 + m->offset = offset;
736 if ((ms->flags & MAGIC_DEBUG) != 0) {
737 mdebug(offset, (char *)(void *)p,
738 @@ -1084,8 +1110,53 @@
743 + /* Verify we have enough data to match magic type */
746 + if (nbytes < (offset + 1)) /* should alway be true */
753 + if (nbytes < (offset + 2))
766 + if (nbytes < (offset + 4))
773 + if (nbytes < (offset + m->vallen))
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");
785 + (void)memcpy(p->buf, s + offset, m->mask + m->vallen);
787 if (!mconvert(ms, p, m))
793 @@ -1179,7 +1250,9 @@
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));
803 regerror(rc, &rx, errmsg, sizeof(errmsg));
804 @@ -1194,6 +1267,31 @@
811 + * search for a string in a certain range
813 + unsigned char *a = (unsigned char*)m->value.s;
814 + unsigned char *b = (unsigned char*)p->buf;
815 + int len = m->vallen;
819 + while (++range <= m->mask) {
820 + while (len-- > 0 && (v = *b++ - *a++) == 0)
823 + m->offset += range-1;
827 + a = (unsigned char*)m->value.s;
828 + b = (unsigned char*)p->buf + range;
834 file_error(ms, 0, "invalid type %d in mcheck()", m->type);