Browse Source

file package update

Signed-off-by: basebuilder_pel7x64builder0 <basebuilder@powerel.org>
master
basebuilder_pel7x64builder0 6 years ago
parent
commit
ae8fd13930
  1. 12
      SOURCES/file-4.17-rpm-name.patch
  2. 98
      SOURCES/file-5.04-generic-msdos.patch
  3. 16
      SOURCES/file-5.04-man-return-code.patch
  4. 53
      SOURCES/file-5.04-minix.patch
  5. 12
      SOURCES/file-5.04-ppc32core.patch
  6. 85
      SOURCES/file-5.04-trim.patch
  7. 10
      SOURCES/file-5.04-volume_key.patch
  8. 12
      SOURCES/file-5.10-sticky-bit.patch
  9. 60
      SOURCES/file-5.10-strength.patch
  10. 27
      SOURCES/file-5.11-CVE-2013-7345.patch
  11. 32
      SOURCES/file-5.11-CVE-2014-0207.patch
  12. 52
      SOURCES/file-5.11-CVE-2014-0237.patch
  13. 39
      SOURCES/file-5.11-CVE-2014-0238.patch
  14. 137
      SOURCES/file-5.11-CVE-2014-1943.patch
  15. 133
      SOURCES/file-5.11-CVE-2014-2270.patch
  16. 41
      SOURCES/file-5.11-CVE-2014-3478.patch
  17. 37
      SOURCES/file-5.11-CVE-2014-3479.patch
  18. 40
      SOURCES/file-5.11-CVE-2014-3480.patch
  19. 34
      SOURCES/file-5.11-CVE-2014-3487.patch
  20. 84
      SOURCES/file-5.11-CVE-2014-3538.patch
  21. 26
      SOURCES/file-5.11-CVE-2014-3587.patch
  22. 35
      SOURCES/file-5.11-CVE-2014-3710.patch
  23. 124
      SOURCES/file-5.11-CVE-2014-8116.patch
  24. 129
      SOURCES/file-5.11-CVE-2014-8117.patch
  25. 34
      SOURCES/file-5.11-CVE-2014-9652.patch
  26. 67
      SOURCES/file-5.11-CVE-2014-9653.patch
  27. 32
      SOURCES/file-5.11-add-aarch64.patch
  28. 564
      SOURCES/file-5.11-auxv.patch
  29. 32
      SOURCES/file-5.11-buildid.patch
  30. 13
      SOURCES/file-5.11-compress.patch
  31. 13
      SOURCES/file-5.11-dump-twice.patch
  32. 56
      SOURCES/file-5.11-exit-code.patch
  33. 30
      SOURCES/file-5.11-gzip-strength.patch
  34. 12
      SOURCES/file-5.11-ia64-swap.patch
  35. 13
      SOURCES/file-5.11-java1718.patch
  36. 32
      SOURCES/file-5.11-magicmgc-home.patch
  37. 14
      SOURCES/file-5.11-newpython.patch
  38. 31
      SOURCES/file-5.11-offset-oob.patch
  39. 16
      SOURCES/file-5.11-pascal.patch
  40. 37
      SOURCES/file-5.11-perl-shebang.patch
  41. 29
      SOURCES/file-5.11-ppc64.patch
  42. 39
      SOURCES/file-5.11-python-comment.patch
  43. 26
      SOURCES/file-5.11-qcow3.patch
  44. 15
      SOURCES/file-5.11-rrdtool.patch
  45. 17
      SOURCES/file-5.11-softmagic-read.patch
  46. 318
      SOURCES/file-5.11-stripped.patch
  47. 23
      SOURCES/file-5.11-swap-info.patch
  48. 27
      SOURCES/file-5.11-version.patch
  49. 47
      SOURCES/file-5.11-xml.patch
  50. 52
      SOURCES/file-5.14-netpbm.patch
  51. 60
      SOURCES/file-localmagic.patch
  52. 13
      SOURCES/file-python-func.patch
  53. 22
      SOURCES/file-qed-vdi-image.patch
  54. 12
      SOURCES/file-tnef.patch
  55. 1022
      SPECS/file.spec

12
SOURCES/file-4.17-rpm-name.patch

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
diff --git a/magic/Magdir/rpm b/magic/Magdir/rpm
index 4eb5556..fe22b3d 100644
--- a/magic/Magdir/rpm
+++ b/magic/Magdir/rpm
@@ -29,6 +29,7 @@
>>8 beshort 17 SuperH
>>8 beshort 18 Xtensa
>>8 beshort 255 noarch
+>>10 string x %s
#delta RPM Daniel Novotny (dnovotny@redhat.com)
0 string drpm Delta RPM

98
SOURCES/file-5.04-generic-msdos.patch

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
diff --git a/magic/Magdir/msdos b/magic/Magdir/msdos
index d1a19a6..9e89f11 100644
--- a/magic/Magdir/msdos
+++ b/magic/Magdir/msdos
@@ -319,9 +319,9 @@
# but it isn't feasible to match all COM files since there must be at least
# two dozen different one-byte "magics".
# test too generic ?
-0 byte 0xe9 DOS executable (COM)
->0x1FE leshort 0xAA55 \b, boot code
->6 string SFX\ of\ LHarc (%s)
+#0 byte 0xe9 DOS executable (COM)
+#>0x1FE leshort 0xAA55 \b, boot code
+#>6 string SFX\ of\ LHarc (%s)
# DOS device driver updated by Joerg Jenderek at May 2011
# http://maben.homeip.net/static/S100/IBM/software/DOS/DOS%20techref/CHAPTER.009
@@ -396,28 +396,28 @@
#>4 uleshort&0x4000 0x4000 \b,control strings-support)
# test too generic ?
-0 byte 0x8c DOS executable (COM)
+#0 byte 0x8c DOS executable (COM)
# updated by Joerg Jenderek at Oct 2008
0 ulelong 0xffff10eb DR-DOS executable (COM)
# byte 0xeb conflicts with "sequent" magic leshort 0xn2eb
-0 ubeshort&0xeb8d >0xeb00
+#0 ubeshort&0xeb8d >0xeb00
# DR-DOS STACKER.COM SCREATE.SYS missed
->0 byte 0xeb
->>0x1FE leshort 0xAA55 DOS executable (COM), boot code
->>85 string UPX DOS executable (COM), UPX compressed
->>4 string \ $ARX DOS executable (COM), ARX self-extracting archive
->>4 string \ $LHarc DOS executable (COM), LHarc self-extracting archive
->>0x20e string SFX\ by\ LARC DOS executable (COM), LARC self-extracting archive
+#>0 byte 0xeb
+#>>0x1FE leshort 0xAA55 DOS executable (COM), boot code
+#>>85 string UPX DOS executable (COM), UPX compressed
+#>>4 string \ $ARX DOS executable (COM), ARX self-extracting archive
+#>>4 string \ $LHarc DOS executable (COM), LHarc self-extracting archive
+#>>0x20e string SFX\ by\ LARC DOS executable (COM), LARC self-extracting archive
# updated by Joerg Jenderek at Oct 2008
#0 byte 0xb8 COM executable
-0 uleshort&0x80ff 0x00b8
+#0 uleshort&0x80ff 0x00b8
# modified by Joerg Jenderek
->1 lelong !0x21cd4cff COM executable for DOS
+#>1 lelong !0x21cd4cff COM executable for DOS
# http://syslinux.zytor.com/comboot.php
# (32-bit COMBOOT) programs *.C32 contain 32-bit code and run in flat-memory 32-bit protected mode
# start with assembler instructions mov eax,21cd4cffh
-0 uleshort&0xc0ff 0xc0b8
->1 lelong 0x21cd4cff COM executable (32-bit COMBOOT)
+#0 uleshort&0xc0ff 0xc0b8
+#>1 lelong 0x21cd4cff COM executable (32-bit COMBOOT)
# syslinux:doc/comboot.txt
# A COM32R program must start with the byte sequence B8 FE 4C CD 21 (mov
# eax,21cd4cfeh) as a magic number.
@@ -437,27 +437,27 @@
# GRR search is not working
#2 search/28 \xcd\x21 COM executable for MS-DOS
#WHICHFAT.cOM
-2 string \xcd\x21 COM executable for DOS
+#2 string \xcd\x21 COM executable for DOS
#DELTREE.cOM DELTREE2.cOM
-4 string \xcd\x21 COM executable for DOS
+#4 string \xcd\x21 COM executable for DOS
#IFMEMDSK.cOM ASSIGN.cOM COMP.cOM
-5 string \xcd\x21 COM executable for DOS
+#5 string \xcd\x21 COM executable for DOS
#DELTMP.COm HASFAT32.cOM
-7 string \xcd\x21
->0 byte !0xb8 COM executable for DOS
+#7 string \xcd\x21
+#>0 byte !0xb8 COM executable for DOS
#COMP.cOM MORE.COm
-10 string \xcd\x21
->5 string !\xcd\x21 COM executable for DOS
+#10 string \xcd\x21
+#>5 string !\xcd\x21 COM executable for DOS
#comecho.com
-13 string \xcd\x21 COM executable for DOS
+#13 string \xcd\x21 COM executable for DOS
#HELP.COm EDIT.coM
-18 string \xcd\x21 COM executable for MS-DOS
+#18 string \xcd\x21 COM executable for MS-DOS
#NWRPLTRM.COm
-23 string \xcd\x21 COM executable for MS-DOS
+#23 string \xcd\x21 COM executable for MS-DOS
#LOADFIX.cOm LOADFIX.cOm
-30 string \xcd\x21 COM executable for MS-DOS
+#30 string \xcd\x21 COM executable for MS-DOS
#syslinux.com 3.11
-70 string \xcd\x21 COM executable for DOS
+#70 string \xcd\x21 COM executable for DOS
# many compressed/converted COMs start with a copy loop instead of a jump
0x6 search/0xa \xfc\x57\xf3\xa5\xc3 COM executable for MS-DOS
0x6 search/0xa \xfc\x57\xf3\xa4\xc3 COM executable for DOS

16
SOURCES/file-5.04-man-return-code.patch

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
diff --git a/doc/file.man b/doc/file.man
index fff7730..3a524f5 100644
--- a/doc/file.man
+++ b/doc/file.man
@@ -542,6 +542,11 @@ program, and are not covered by the above license.
.Sh RETURN CODE
.Nm
returns 0 on success, and non-zero on error.
+.Pp
+If the file named by the file
+operand does not exist, cannot be read, or the type of the file named by
+the file operand cannot be determined, this is not be considered an error
+that affects the exit status.
.Sh BUGS
.Pp
Please report bugs and send patches to the bug tracker at

53
SOURCES/file-5.04-minix.patch

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
index 9172dcb..25c24ca 100644
--- a/magic/Magdir/filesystems
+++ b/magic/Magdir/filesystems
@@ -885,32 +885,40 @@
# Minix filesystems - Juan Cespedes <cespedes@debian.org>
0x410 leshort 0x137f
!:strength / 2
->0x402 beshort < 100 Minix filesystem, V1, %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V1, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x137f
!:strength / 2
->0x402 beshort < 100 Minix filesystem, V1 (big endian), %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V1 (big endian), %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x138f
!:strength / 2
->0x402 beshort < 100 Minix filesystem, V1, 30 char names, %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V1, 30 char names, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x138f
!:strength / 2
->0x402 beshort < 100 Minix filesystem, V1, 30 char names (big endian), %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V1, 30 char names (big endian), %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x2468
->0x402 beshort < 100 Minix filesystem, V2, %d zones
+>0x402 beshort < 100
+>>0x402 beshort > -1 Minix filesystem, V2, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x2468
->0x402 beshort < 100 Minix filesystem, V2 (big endian), %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V2 (big endian), %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x2478
->0x402 beshort < 100 Minix filesystem, V2, 30 char names, %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V2, 30 char names, %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x2478
->0x402 beshort < 100 Minix filesystem, V2, 30 char names, %d zones
+>0x402 beshort < 100
+>0x402 beshort > -1 Minix filesystem, V2, 30 char names, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x2478
>0x402 beshort !0 Minix filesystem, V2, 30 char names (big endian), %d zones

12
SOURCES/file-5.04-ppc32core.patch

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
diff --git a/src/readelf.c b/src/readelf.c
index 823db6e..9651239 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -218,6 +218,7 @@ static const size_t prpsoffsets32[] = {
100, /* SunOS 5.x (command line) */
84, /* SunOS 5.x (short name) */
+ 48, /* PowerPC */
44, /* Linux (command line) */
28, /* Linux 2.0.36 (short name) */

85
SOURCES/file-5.04-trim.patch

@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
index a2c2966..ecfa6c2 100644
--- a/magic/Magdir/filesystems
+++ b/magic/Magdir/filesystems
@@ -1251,7 +1251,7 @@
>>38917 byte >0x33 (unknown version, ID 0x%X)
>>38917 byte <0x31 (unknown version, ID 0x%X)
# "application id" which appears to be used as a volume label
->32808 string >\0 '%s'
+>32808 string/T >\0 '%s'
>34816 string \000CD001\001EL\ TORITO\ SPECIFICATION (bootable)
37633 string CD001 ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)
!:mime application/x-iso9660-image
diff --git a/src/apprentice.c b/src/apprentice.c
index 0490642..6dd8381 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -1452,6 +1452,9 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
goto bad;
m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;
break;
+ case CHAR_TRIM:
+ m->str_flags |= STRING_TRIM;
+ break;
default:
bad:
if (ms->flags & MAGIC_CHECK)
diff --git a/src/file.h b/src/file.h
index e02009f..1b5f53f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -307,6 +307,7 @@ struct magic {
#define PSTRING_LEN \
(PSTRING_1_BE|PSTRING_2_LE|PSTRING_2_BE|PSTRING_4_LE|PSTRING_4_BE)
#define PSTRING_LENGTH_INCLUDES_ITSELF BIT(12)
+#define STRING_TRIM BIT(13)
#define CHAR_COMPACT_WHITESPACE 'W'
#define CHAR_COMPACT_OPTIONAL_WHITESPACE 'w'
#define CHAR_IGNORE_LOWERCASE 'c'
@@ -321,6 +322,7 @@ struct magic {
#define CHAR_PSTRING_4_BE 'L'
#define CHAR_PSTRING_4_LE 'l'
#define CHAR_PSTRING_LENGTH_INCLUDES_ITSELF 'J'
+#define CHAR_TRIM 'T'
#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
#define STRING_DEFAULT_RANGE 100
diff --git a/src/softmagic.c b/src/softmagic.c
index 8d08cad..f084edd 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -451,11 +451,30 @@ mprint(struct magic_set *ms, struct magic *m)
t = ms->offset + m->vallen;
}
else {
+ char *str = p->s;
+
+ /* compute t before we mangle the string? */
+ t = ms->offset + strlen(str);
+
if (*m->value.s == '\0')
- p->s[strcspn(p->s, "\n")] = '\0';
- if (file_printf(ms, m->desc, p->s) == -1)
+ str[strcspn(str, "\n")] = '\0';
+
+ if (m->str_flags & STRING_TRIM) {
+ char *last;
+ while (isspace((unsigned char)*str))
+ str++;
+ last = str;
+ while (*last)
+ last++;
+ --last;
+ while (isspace((unsigned char)*last))
+ last--;
+ *++last = '\0';
+ }
+
+ if (file_printf(ms, m->desc, str) == -1)
return -1;
- t = ms->offset + strlen(p->s);
+
if (m->type == FILE_PSTRING)
t += file_pstring_length_size(m);
}

10
SOURCES/file-5.04-volume_key.patch

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
diff --git a/magic/Magdir/securitycerts b/magic/Magdir/securitycerts
index 8785dd8..1c340be 100644
--- a/magic/Magdir/securitycerts
+++ b/magic/Magdir/securitycerts
@@ -4,3 +4,5 @@
0 search/1 -----BEGIN\ CERTIFICATE------ RFC1421 Security Certificate text
0 search/1 -----BEGIN\ NEW\ CERTIFICATE RFC1421 Security Certificate Signing Request text
0 belong 0xedfeedfe Sun 'jks' Java Keystore File data
+
+0 string \0volume_key volume_key escrow packet

12
SOURCES/file-5.10-sticky-bit.patch

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
diff --git a/src/ascmagic.c b/src/ascmagic.c
index 5a1caac..8d6ca95 100644
--- a/src/ascmagic.c
+++ b/src/ascmagic.c
@@ -211,6 +211,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
case 0:
if (file_printf(ms, ", ") == -1)
goto done;
+ break;
case -1:
goto done;
default:

60
SOURCES/file-5.10-strength.patch

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
diff --git a/magic/Magdir/c-lang b/magic/Magdir/c-lang
index 0665627..fdefa8c 100644
--- a/magic/Magdir/c-lang
+++ b/magic/Magdir/c-lang
@@ -6,26 +6,36 @@
# BCPL
0 search/8192 "libhdr" BCPL source text
!:mime text/x-bcpl
+!:strength / 2
0 search/8192 "LIBHDR" BCPL source text
!:mime text/x-bcpl
+!:strength / 2
# C
0 regex \^#include C source text
!:mime text/x-c
+!:strength / 2
0 regex \^char C source text
!:mime text/x-c
+!:strength / 2
0 regex \^double C source text
!:mime text/x-c
+!:strength / 2
0 regex \^extern C source text
!:mime text/x-c
+!:strength / 2
0 regex \^float C source text
!:mime text/x-c
+!:strength / 2
0 regex \^struct C source text
!:mime text/x-c
+!:strength / 2
0 regex \^union C source text
!:mime text/x-c
+!:strength / 2
0 search/8192 main( C source text
!:mime text/x-c
+!:strength / 2
# C++
# The strength of these rules is increased so they beat the C rules above
diff --git a/magic/Magdir/perl b/magic/Magdir/perl
index e11f2ab..b02b2c2 100644
--- a/magic/Magdir/perl
+++ b/magic/Magdir/perl
@@ -28,10 +28,14 @@
# check the first line
0 search/1 package
>0 regex \^package[\ \t]+[0-9A-Za-z_:]+\ *; Perl5 module source text
+# to be tried before C source
+!:strength + 5
# not 'p', check other lines
0 search/1 !p
>0 regex \^package[\ \t]+[0-9A-Za-z_:]+\ *;
>>0 regex \^1\ *;|\^(use|sub|my)\ .*[(;{=] Perl5 module source text
+# to be tried before C source
+!:strength + 40

27
SOURCES/file-5.11-CVE-2013-7345.patch

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
From ef2329cf71acb59204dd981e2c6cce6c81fe467c Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 25 Mar 2013 14:06:55 +0000
Subject: [PATCH] limit to 100 repetitions to avoid excessive backtracking
Carsten Wolff

---
magic/Magdir/commands | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/magic/Magdir/commands b/magic/Magdir/commands
index 67c3eee..4a7d8dd 100644
--- a/magic/Magdir/commands
+++ b/magic/Magdir/commands
@@ -49,7 +49,8 @@
!:mime text/x-awk
0 string/wt #!\ /usr/bin/awk awk script text executable
!:mime text/x-awk
-0 regex =^\\s*BEGIN\\s*[{] awk script text
+0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text
+!:strength - 12
# AT&T Bell Labs' Plan 9 shell
0 string/wt #!\ /bin/rc Plan 9 rc shell script text executable
--
1.8.5.5

32
SOURCES/file-5.11-CVE-2014-0207.patch

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
From 4fcb9a9d1b1063a65fbeb27395de4979c75bd962 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Tue, 3 Jun 2014 11:05:00 +0200
Subject: [PATCH] Fix bug #67326 fileinfo: cdf_read_short_sector insufficient
boundary check

Upstream fix https://github.com/file/file/commit/6d209c1c489457397a5763bca4b28e43aac90391.patch
Only revelant part applied
---
ext/fileinfo/libmagic/cdf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index 4712e84..16649f1 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -352,10 +352,10 @@ cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
size_t ss = CDF_SHORT_SEC_SIZE(h);
size_t pos = CDF_SHORT_SEC_POS(h, id);
assert(ss == len);
- if (pos > CDF_SEC_SIZE(h) * sst->sst_len) {
+ if (pos + len > CDF_SEC_SIZE(h) * sst->sst_len) {
DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
SIZE_T_FORMAT "u\n",
- pos, CDF_SEC_SIZE(h) * sst->sst_len));
+ pos + len, CDF_SEC_SIZE(h) * sst->sst_len));
return -1;
}
(void)memcpy(((char *)buf) + offs,
--
1.9.2

52
SOURCES/file-5.11-CVE-2014-0237.patch

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
From 68ce2d0ea6da79b12a365e375e1c2ce882c77480 Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Mon, 26 May 2014 17:50:14 -0700
Subject: [PATCH] Fix bug #67328 (fileinfo: numerous file_printf calls
resulting in performance degradation)

Upstream patch: https://github.com/file/file/commit/b8acc83781d5a24cc5101e525d15efe0482c280d
---
ext/fileinfo/libmagic/cdf.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index dd7177e..8dacd2f 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -929,7 +929,7 @@ int
cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
cdf_summary_info_header_t *ssi, cdf_property_info_t **info, size_t *count)
{
- size_t i, maxcount;
+ size_t maxcount;
const cdf_summary_info_header_t *si =
CAST(const cdf_summary_info_header_t *, sst->sst_tab);
const cdf_section_declaration_t *sd =
@@ -944,21 +944,13 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
ssi->si_os = CDF_TOLE2(si->si_os);
ssi->si_class = si->si_class;
cdf_swap_class(&ssi->si_class);
- ssi->si_count = CDF_TOLE2(si->si_count);
+ ssi->si_count = CDF_TOLE4(si->si_count);
*count = 0;
maxcount = 0;
*info = NULL;
- for (i = 0; i < CDF_TOLE4(si->si_count); i++) {
- if (i >= CDF_LOOP_LIMIT) {
- DPRINTF(("Unpack summary info loop limit"));
- errno = EFTYPE;
- return -1;
- }
- if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset),
- info, count, &maxcount) == -1) {
+ if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset), info,
+ count, &maxcount) == -1)
return -1;
- }
- }
return 0;
}
--
1.9.2

39
SOURCES/file-5.11-CVE-2014-0238.patch

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
From 22736b7c56d678f142d5dd21f4996e5819507a2b Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Mon, 26 May 2014 17:42:18 -0700
Subject: [PATCH] Fix bug #67327: fileinfo: CDF infinite loop in nelements DoS

Upstream fix: https://github.com/file/file/commit/f97486ef5dc3e8735440edc4fc8808c63e1a3ef0
---
ext/fileinfo/libmagic/cdf.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index 8dacd2f..4712e84 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -810,6 +810,10 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
if (inp[i].pi_type & CDF_VECTOR) {
nelements = CDF_GETUINT32(q, 1);
+ if (nelements == 0) {
+ DPRINTF(("CDF_VECTOR with nelements == 0\n"));
+ goto out;
+ }
o = 2;
} else {
nelements = 1;
@@ -884,7 +888,9 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
}
DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
nelements));
- for (j = 0; j < nelements; j++, i++) {
+ for (j = 0; j < nelements && i < sh.sh_properties;
+ j++, i++)
+ {
uint32_t l = CDF_GETUINT32(q, o);
inp[i].pi_str.s_len = l;
inp[i].pi_str.s_buf = (const char *)
--
1.9.2

137
SOURCES/file-5.11-CVE-2014-1943.patch

@ -0,0 +1,137 @@ @@ -0,0 +1,137 @@
diff --git a/src/ascmagic.c b/src/ascmagic.c
index 8d6ca95..cfa3951 100644
--- a/src/ascmagic.c
+++ b/src/ascmagic.c
@@ -147,7 +147,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
== NULL)
goto done;
if ((rv = file_softmagic(ms, utf8_buf,
- (size_t)(utf8_end - utf8_buf), TEXTTEST, text)) == 0)
+ (size_t)(utf8_end - utf8_buf), 0, TEXTTEST, text)) == 0)
rv = -1;
}
diff --git a/src/file.h b/src/file.h
index 175f659..e02009f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -414,7 +414,7 @@ protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
unichar **, size_t *, const char **, const char **, const char **);
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
- int, int);
+ size_t, int, int);
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
protected uint64_t file_signextend(struct magic_set *, struct magic *,
uint64_t);
diff --git a/src/funcs.c b/src/funcs.c
index 0b2a3d0..0d645eb 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -228,7 +228,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
/* try soft magic tests */
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
- if ((m = file_softmagic(ms, ubuf, nb, BINTEST,
+ if ((m = file_softmagic(ms, ubuf, nb, 0, BINTEST,
looks_text)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "softmagic %d\n", m);
diff --git a/src/softmagic.c b/src/softmagic.c
index 22e1190..56f09ee 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -41,11 +41,12 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.147 2011/11/05 15:44:22 rrt Exp $")
#include <stdlib.h>
#include <time.h>
+#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) >= ((n) - (o)))
private int match(struct magic_set *, struct magic *, uint32_t,
- const unsigned char *, size_t, int, int);
+ const unsigned char *, size_t, int, int, int);
private int mget(struct magic_set *, const unsigned char *,
- struct magic *, size_t, unsigned int, int);
+ struct magic *, size_t, unsigned int, int, int);
private int magiccheck(struct magic_set *, struct magic *);
private int32_t mprint(struct magic_set *, struct magic *);
private int32_t moffset(struct magic_set *, struct magic *);
@@ -67,13 +68,13 @@ private void cvt_64(union VALUETYPE *, const struct magic *);
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
protected int
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
- int mode, int text)
+ size_t level, int mode, int text)
{
struct mlist *ml;
int rv;
for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode,
- text)) != 0)
+ text, level)) != 0)
return rv;
return 0;
@@ -108,7 +109,8 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
*/
private int
match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
- const unsigned char *s, size_t nbytes, int mode, int text)
+ const unsigned char *s, size_t nbytes, int mode, int text,
+ int recursion_level)
{
uint32_t magindex = 0;
unsigned int cont_level = 0;
@@ -140,7 +142,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
ms->line = m->lineno;
/* if main entry matches, print it... */
- switch (mget(ms, s, m, nbytes, cont_level, text)) {
+ switch (mget(ms, s, m, nbytes, cont_level, text, recursion_level + 1)) {
case -1:
return -1;
case 0:
@@ -223,7 +225,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
continue;
}
#endif
- switch (mget(ms, s, m, nbytes, cont_level, text)) {
+ switch (mget(ms, s, m, nbytes, cont_level, text, recursion_level + 1)) {
case -1:
return -1;
case 0:
@@ -1018,12 +1020,18 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
private int
mget(struct magic_set *ms, const unsigned char *s,
- struct magic *m, size_t nbytes, unsigned int cont_level, int text)
+ struct magic *m, size_t nbytes, unsigned int cont_level, int text,
+ int recursion_level)
{
uint32_t offset = ms->offset;
uint32_t count = m->str_range;
union VALUETYPE *p = &ms->ms_value;
+ if (recursion_level >= 20) {
+ file_error(ms, 0, "recursion nesting exceeded");
+ return -1;
+ }
+
if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1)
return -1;
@@ -1580,10 +1588,12 @@ mget(struct magic_set *ms, const unsigned char *s,
if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
file_printf(ms, "%s", m->desc) == -1)
return -1;
- if (nbytes < offset)
+ if (offset == 0)
return 0;
+ if (OFFSET_OOB(nbytes, offset, 0))
+ return 0;
return file_softmagic(ms, s + offset, nbytes - offset,
- BINTEST, text);
+ recursion_level, BINTEST, text);
case FILE_DEFAULT: /* nothing to check */
default:

133
SOURCES/file-5.11-CVE-2014-2270.patch

@ -0,0 +1,133 @@ @@ -0,0 +1,133 @@
diff --git a/src/softmagic.c b/src/softmagic.c
index 56f09ee..8d08cad 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -61,6 +61,7 @@ private void cvt_16(union VALUETYPE *, const struct magic *);
private void cvt_32(union VALUETYPE *, const struct magic *);
private void cvt_64(union VALUETYPE *, const struct magic *);
+#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
/*
* softmagic - lookup one file in parsed, in-memory copy of database
* Passed the name and FILE * of one file to be typed.
@@ -1081,7 +1082,7 @@ mget(struct magic_set *ms, const unsigned char *s,
}
switch (m->in_type) {
case FILE_BYTE:
- if (nbytes < (offset + 1))
+ if (OFFSET_OOB(nbytes, offset, 1))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1116,7 +1117,8 @@ mget(struct magic_set *ms, const unsigned char *s,
offset = ~offset;
break;
case FILE_BESHORT:
- if (nbytes < (offset + 2))
+
+ if (OFFSET_OOB(nbytes, offset, 2))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1168,7 +1170,7 @@ mget(struct magic_set *ms, const unsigned char *s,
offset = ~offset;
break;
case FILE_LESHORT:
- if (nbytes < (offset + 2))
+ if (OFFSET_OOB(nbytes, offset, 2))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1220,7 +1222,7 @@ mget(struct magic_set *ms, const unsigned char *s,
offset = ~offset;
break;
case FILE_SHORT:
- if (nbytes < (offset + 2))
+ if (OFFSET_OOB(nbytes, offset, 2))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1257,7 +1259,7 @@ mget(struct magic_set *ms, const unsigned char *s,
break;
case FILE_BELONG:
case FILE_BEID3:
- if (nbytes < (offset + 4))
+ if (OFFSET_OOB(nbytes, offset, 4))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1328,7 +1330,7 @@ mget(struct magic_set *ms, const unsigned char *s,
break;
case FILE_LELONG:
case FILE_LEID3:
- if (nbytes < (offset + 4))
+ if (OFFSET_OOB(nbytes, offset, 4))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1398,7 +1400,7 @@ mget(struct magic_set *ms, const unsigned char *s,
offset = ~offset;
break;
case FILE_MELONG:
- if (nbytes < (offset + 4))
+ if (OFFSET_OOB(nbytes, offset, 4))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1468,7 +1470,7 @@ mget(struct magic_set *ms, const unsigned char *s,
offset = ~offset;
break;
case FILE_LONG:
- if (nbytes < (offset + 4))
+ if (OFFSET_OOB(nbytes, offset, 4))
return 0;
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
@@ -1535,14 +1537,14 @@ mget(struct magic_set *ms, const unsigned char *s,
/* Verify we have enough data to match magic type */
switch (m->type) {
case FILE_BYTE:
- if (nbytes < (offset + 1)) /* should alway be true */
+ if (OFFSET_OOB(nbytes, offset, 1))
return 0;
break;
case FILE_SHORT:
case FILE_BESHORT:
case FILE_LESHORT:
- if (nbytes < (offset + 2))
+ if (OFFSET_OOB(nbytes, offset, 2))
return 0;
break;
@@ -1561,26 +1563,26 @@ mget(struct magic_set *ms, const unsigned char *s,
case FILE_FLOAT:
case FILE_BEFLOAT:
case FILE_LEFLOAT:
- if (nbytes < (offset + 4))
+ if (OFFSET_OOB(nbytes, offset, 4))
return 0;
break;
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
- if (nbytes < (offset + 8))
+ if (OFFSET_OOB(nbytes, offset, 8))
return 0;
break;
case FILE_STRING:
case FILE_PSTRING:
case FILE_SEARCH:
- if (nbytes < (offset + m->vallen))
+ if (OFFSET_OOB(nbytes, offset, m->vallen))
return 0;
break;
case FILE_REGEX:
- if (nbytes < offset)
+ if (OFFSET_OOB(nbytes, offset, 0))
return 0;
break;

41
SOURCES/file-5.11-CVE-2014-3478.patch

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
From e77659a8c87272e5061738a31430d2111482c426 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Tue, 10 Jun 2014 14:02:36 +0200
Subject: [PATCH] Fixed Bug #67410 fileinfo: mconvert incorrect handling of
truncated pascal string size

Upstream
https://github.com/file/file/commit/27a14bc7ba285a0a5ebfdb55e54001aa11932b08
---
ext/fileinfo/libmagic/softmagic.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index 21fea6b..01e4977 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -818,10 +818,18 @@ mconvert(struct magic_set *ms, struct magic *m)
return 1;
}
case FILE_PSTRING: {
- char *ptr1 = p->s, *ptr2 = ptr1 + file_pstring_length_size(m);
+ size_t sz = file_pstring_length_size(m);
+ char *ptr1 = p->s, *ptr2 = ptr1 + sz;
size_t len = file_pstring_get_length(m, ptr1);
- if (len >= sizeof(p->s))
- len = sizeof(p->s) - 1;
+ if (len >= sizeof(p->s)) {
+ /*
+ * The size of the pascal string length (sz)
+ * is 1, 2, or 4. We need at least 1 byte for NUL
+ * termination, but we've already truncated the
+ * string by p->s, so we need to deduct sz.
+ */
+ len = sizeof(p->s) - sz;
+ }
while (len--)
*ptr1++ = *ptr2++;
*ptr1 = '\0';
--
1.9.2

37
SOURCES/file-5.11-CVE-2014-3479.patch

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
From 5c9f96799961818944d43b22c241cc56c215c2e4 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Tue, 10 Jun 2014 14:13:14 +0200
Subject: [PATCH] Fixed Bug #67411 fileinfo: cdf_check_stream_offset
insufficient boundary check

Upstream:
https://github.com/file/file/commit/36fadd29849b8087af9f4586f89dbf74ea45be67
---
ext/fileinfo/libmagic/cdf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index 16649f1..c9a5d50 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -267,13 +267,15 @@ cdf_check_stream_offset(const cdf_stream_t *sst, const cdf_header_t *h,
{
const char *b = (const char *)sst->sst_tab;
const char *e = ((const char *)p) + tail;
+ size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ?
+ CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h);
(void)&line;
- if (e >= b && (size_t)(e - b) < CDF_SEC_SIZE(h) * sst->sst_len)
+ if (e >= b && (size_t)(e - b) <= ss * sst->sst_len)
return 0;
DPRINTF(("%d: offset begin %p end %p %" SIZE_T_FORMAT "u"
" >= %" SIZE_T_FORMAT "u [%" SIZE_T_FORMAT "u %"
SIZE_T_FORMAT "u]\n", line, b, e, (size_t)(e - b),
- CDF_SEC_SIZE(h) * sst->sst_len, CDF_SEC_SIZE(h), sst->sst_len));
+ ss * sst->sst_len, ss, sst->sst_len));
errno = EFTYPE;
return -1;
}
--
1.9.2

40
SOURCES/file-5.11-CVE-2014-3480.patch

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
From 40ef6e07e0b2cdced57c506e08cf18f47122292d Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Tue, 10 Jun 2014 14:22:04 +0200
Subject: [PATCH] Bug #67412 fileinfo: cdf_count_chain insufficient
boundary check

Upstream:
https://github.com/file/file/commit/40bade80cbe2af1d0b2cd0420cebd5d5905a2382
---
ext/fileinfo/libmagic/cdf.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index c9a5d50..ee467a6 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -457,7 +457,8 @@ size_t
cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
{
size_t i, j;
- cdf_secid_t maxsector = (cdf_secid_t)(sat->sat_len * size);
+ cdf_secid_t maxsector = (cdf_secid_t)((sat->sat_len * size)
+ / sizeof(maxsector));
DPRINTF(("Chain:"));
for (j = i = 0; sid >= 0; i++, j++) {
@@ -467,8 +468,8 @@ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
errno = EFTYPE;
return (size_t)-1;
}
- if (sid > maxsector) {
- DPRINTF(("Sector %d > %d\n", sid, maxsector));
+ if (sid >= maxsector) {
+ DPRINTF(("Sector %d >= %d\n", sid, maxsector));
errno = EFTYPE;
return (size_t)-1;
}
--
1.9.2

34
SOURCES/file-5.11-CVE-2014-3487.patch

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
From 25b1dc917a53787dbb2532721ca22f3f36eb13c0 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Tue, 10 Jun 2014 14:33:37 +0200
Subject: [PATCH] Fixed Bug #67413 fileinfo: cdf_read_property_info
insufficient boundary chec

Upstream:
https://github.com/file/file/commit/93e063ee374b6a75729df9e7201fb511e47e259d

Adapted for C standard.
---
ext/fileinfo/libmagic/cdf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index ee467a6..429f3b9 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -799,7 +799,11 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
if (cdf_check_stream_offset(sst, h, e, 0, __LINE__) == -1)
goto out;
for (i = 0; i < sh.sh_properties; i++) {
- size_t ofs = CDF_GETUINT32(p, (i << 1) + 1);
+ size_t ofs, tail = (i << 1) + 1;
+ if (cdf_check_stream_offset(sst, h, p, tail * sizeof(uint32_t),
+ __LINE__) == -1)
+ goto out;
+ ofs = CDF_GETUINT32(p, tail);
q = (const uint8_t *)(const void *)
((const char *)(const void *)p + ofs
- 2 * sizeof(uint32_t));
--
1.9.2

84
SOURCES/file-5.11-CVE-2014-3538.patch

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
diff --git a/src/softmagic.c b/src/softmagic.c
index f848f94..ee979b9 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -50,7 +50,7 @@ private int32_t mprint(struct magic_set *, struct magic *);
private int32_t moffset(struct magic_set *, struct magic *);
private void mdebug(uint32_t, const char *, size_t);
private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
- const unsigned char *, uint32_t, size_t, size_t);
+ const unsigned char *, uint32_t, size_t, struct magic *);
private int mconvert(struct magic_set *, struct magic *);
private int print_sep(struct magic_set *, int);
private int handle_annotation(struct magic_set *, struct magic *);
@@ -936,7 +936,7 @@ mdebug(uint32_t offset, const char *str, size_t len)
private int
mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
- const unsigned char *s, uint32_t offset, size_t nbytes, size_t linecnt)
+ const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m)
{
/*
* Note: FILE_SEARCH and FILE_REGEX do not actually copy
@@ -956,15 +956,24 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
const char *last; /* end of search region */
const char *buf; /* start of search region */
const char *end;
- size_t lines;
+ size_t lines, linecnt, bytecnt;
+ linecnt = m->str_range;
+ bytecnt = linecnt * 80;
+
+ if (bytecnt == 0) {
+ bytecnt = 8192;
+ }
+ if (bytecnt > nbytes) {
+ bytecnt = nbytes;
+ }
if (s == NULL) {
ms->search.s_len = 0;
ms->search.s = NULL;
return 0;
}
buf = RCAST(const char *, s) + offset;
- end = last = RCAST(const char *, s) + nbytes;
+ end = last = RCAST(const char *, s) + bytecnt;
/* mget() guarantees buf <= last */
for (lines = linecnt, b = buf; lines && b < end &&
((b = CAST(const char *,
@@ -977,7 +986,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
b++;
}
if (lines)
- last = RCAST(const char *, s) + nbytes;
+ last = RCAST(const char *, s) + bytecnt;
ms->search.s = buf;
ms->search.s_len = last - buf;
@@ -1050,7 +1059,6 @@ mget(struct magic_set *ms, const unsigned char *s,
int recursion_level)
{
uint32_t offset = ms->offset;
- uint32_t count = m->str_range;
union VALUETYPE *p = &ms->ms_value;
if (recursion_level >= 20) {
@@ -1058,7 +1066,7 @@ mget(struct magic_set *ms, const unsigned char *s,
return -1;
}
- if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1)
+ if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, (uint32_t)nbytes, m) == -1)
return -1;
if ((ms->flags & MAGIC_DEBUG) != 0) {
@@ -1546,7 +1554,7 @@ mget(struct magic_set *ms, const unsigned char *s,
if (m->flag & INDIROFFADD) {
offset += ms->c.li[cont_level-1].off;
}
- if (mcopy(ms, p, m->type, 0, s, offset, nbytes, count) == -1)
+ if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1)
return -1;
ms->offset = offset;

26
SOURCES/file-5.11-CVE-2014-3587.patch

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
From 7ba1409a1aee5925180de546057ddd84ff267947 Mon Sep 17 00:00:00 2001
From: Remi Collet <rcollet@redhat.com>
Date: Thu, 14 Aug 2014 17:19:03 -0700
Subject: [PATCH] Fix bug #67716 - Segfault in cdf.c

---
NEWS | 1 +
ext/fileinfo/libmagic/cdf.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c
index 429f3b9..2c0a2d9 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -807,7 +807,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
q = (const uint8_t *)(const void *)
((const char *)(const void *)p + ofs
- 2 * sizeof(uint32_t));
- if (q > e) {
+ if (q < p || q > e) {
DPRINTF(("Ran of the end %p > %p\n", q, e));
goto out;
}
--
1.9.2

35
SOURCES/file-5.11-CVE-2014-3710.patch

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
From 1803228597e82218a8c105e67975bc50e6f5bf0d Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Wed, 22 Oct 2014 15:37:04 +0200
Subject: [PATCH] Fix bug #68283: fileinfo: out-of-bounds read in elf note
headers

Upstream commit
https://github.com/file/file/commit/39c7ac1106be844a5296d3eb5971946cc09ffda0

CVE -2014-3710
---
ext/fileinfo/libmagic/readelf.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/ext/fileinfo/libmagic/readelf.c b/ext/fileinfo/libmagic/readelf.c
index 1c3845f..bb6f70f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -366,6 +366,13 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
uint32_t namesz, descsz;
unsigned char *nbuf = CAST(unsigned char *, vbuf);
+ if (xnh_sizeof + offset > size) {
+ /*
+ * We're out of note headers.
+ */
+ return xnh_sizeof + offset;
+ }
+
(void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
offset += xnh_sizeof;
--
2.1.0

124
SOURCES/file-5.11-CVE-2014-8116.patch

@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
diff --git a/src/elfclass.h b/src/elfclass.h
index 010958a..0826ce3 100644
--- a/src/elfclass.h
+++ b/src/elfclass.h
@@ -35,10 +35,12 @@
switch (type) {
#ifdef ELFCORE
case ET_CORE:
+ phnum = elf_getu16(swap, elfhdr.e_phnum);
+ if (phnum > MAX_PHNUM)
+ return toomany(ms, "program", phnum);
flags |= FLAGS_IS_CORE;
if (dophn_core(ms, clazz, swap, fd,
- (off_t)elf_getu(swap, elfhdr.e_phoff),
- elf_getu16(swap, elfhdr.e_phnum),
+ (off_t)elf_getu(swap, elfhdr.e_phoff), phnum,
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
fsize, &flags) == -1)
return -1;
@@ -46,18 +48,24 @@
#endif
case ET_EXEC:
case ET_DYN:
+ phnum = elf_getu16(swap, elfhdr.e_phnum);
+ if (phnum > MAX_PHNUM)
+ return toomany(ms, "program", phnum);
+ shnum = elf_getu16(swap, elfhdr.e_shnum);
+ if (shnum > MAX_SHNUM)
+ return toomany(ms, "section", shnum);
if (dophn_exec(ms, clazz, swap, fd,
- (off_t)elf_getu(swap, elfhdr.e_phoff),
- elf_getu16(swap, elfhdr.e_phnum),
+ (off_t)elf_getu(swap, elfhdr.e_phoff), phnum,
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
- fsize, &flags, elf_getu16(swap, elfhdr.e_shnum))
- == -1)
+ fsize, &flags, shnum) == -1)
return -1;
/*FALLTHROUGH*/
case ET_REL:
+ shnum = elf_getu16(swap, elfhdr.e_shnum);
+ if (shnum > MAX_SHNUM)
+ return toomany(ms, "section", shnum);
if (doshn(ms, clazz, swap, fd,
- (off_t)elf_getu(swap, elfhdr.e_shoff),
- elf_getu16(swap, elfhdr.e_shnum),
+ (off_t)elf_getu(swap, elfhdr.e_shoff), shnum,
(size_t)elf_getu16(swap, elfhdr.e_shentsize),
fsize, &flags, elf_getu16(swap, elfhdr.e_machine),
(int)elf_getu16(swap, elfhdr.e_shstrndx)) == -1)
diff --git a/src/readelf.c b/src/readelf.c
index de016b5..1f4d1f4 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -60,6 +60,18 @@ private uint16_t getu16(int, uint16_t);
private uint32_t getu32(int, uint32_t);
private uint64_t getu64(int, uint64_t);
+#define MAX_PHNUM 2048
+#define MAX_SHNUM 32768
+
+private int
+toomany(struct magic_set *ms, const char *name, uint16_t num)
+{
+ if (file_printf(ms, ", too many %s header sections (%u)", name, num
+ ) == -1)
+ return -1;
+ return 0;
+}
+
private uint16_t
getu16(int swap, uint16_t value)
{
@@ -388,13 +400,13 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
if (namesz & 0x80000000) {
(void)file_printf(ms, ", bad note name size 0x%lx",
(unsigned long)namesz);
- return offset;
+ return 0;
}
if (descsz & 0x80000000) {
(void)file_printf(ms, ", bad note description size 0x%lx",
(unsigned long)descsz);
- return offset;
+ return 0;
}
@@ -851,6 +863,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
Elf32_Shdr sh32;
Elf64_Shdr sh64;
int stripped = 1;
+ size_t nbadcap = 0;
void *nbuf;
off_t noff, coff, name_off;
uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
@@ -928,6 +941,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
free(nbuf);
break;
case SHT_SUNW_cap:
+ if (nbadcap > 5)
+ break;
if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
@@ -963,6 +978,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
(unsigned long long)xcap_tag,
(unsigned long long)xcap_val) == -1)
return -1;
+ if (nbadcap++ > 2)
+ coff = xsh_size;
break;
}
}
@@ -1142,7 +1159,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
int flags = 0;
Elf32_Ehdr elf32hdr;
Elf64_Ehdr elf64hdr;
- uint16_t type;
+ uint16_t type, phnum, shnum;
if (ms->flags & (MAGIC_MIME|MAGIC_APPLE))
return 0;

129
SOURCES/file-5.11-CVE-2014-8117.patch

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
diff --git a/src/file.h b/src/file.h
index 28f9bc7..f55d47f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -446,6 +446,14 @@ protected int file_os2_apptype(struct magic_set *, const char *, const void *,
#endif /* __EMX__ */
+typedef struct {
+ char *buf;
+ uint32_t offset;
+} file_pushbuf_t;
+
+protected file_pushbuf_t *file_push_buffer(struct magic_set *);
+protected char *file_pop_buffer(struct magic_set *, file_pushbuf_t *);
+
#ifndef COMPILE_ONLY
extern const char *file_names[];
extern const size_t file_nnames;
diff --git a/src/funcs.c b/src/funcs.c
index 0d645eb..04bab02 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -459,3 +459,43 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
return nm;
}
}
+
+protected file_pushbuf_t *
+file_push_buffer(struct magic_set *ms)
+{
+ file_pushbuf_t *pb;
+
+ if (ms->event_flags & EVENT_HAD_ERR)
+ return NULL;
+
+ if ((pb = (CAST(file_pushbuf_t *, malloc(sizeof(*pb))))) == NULL)
+ return NULL;
+
+ pb->buf = ms->o.buf;
+ pb->offset = ms->offset;
+
+ ms->o.buf = NULL;
+ ms->offset = 0;
+
+ return pb;
+}
+
+protected char *
+file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb)
+{
+ char *rbuf;
+
+ if (ms->event_flags & EVENT_HAD_ERR) {
+ free(pb->buf);
+ free(pb);
+ return NULL;
+ }
+
+ rbuf = ms->o.buf;
+
+ ms->o.buf = pb->buf;
+ ms->offset = pb->offset;
+
+ free(pb);
+ return rbuf;
+}
diff --git a/src/softmagic.c b/src/softmagic.c
index ee979b9..3695add 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -60,6 +60,7 @@ private void cvt_32(union VALUETYPE *, const struct magic *);
private void cvt_64(union VALUETYPE *, const struct magic *);
#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
+
/*
* softmagic - lookup one file in parsed, in-memory copy of database
* Passed the name and FILE * of one file to be typed.
@@ -1060,6 +1061,9 @@ mget(struct magic_set *ms, const unsigned char *s,
{
uint32_t offset = ms->offset;
union VALUETYPE *p = &ms->ms_value;
+ file_pushbuf_t *pb;
+ char *rbuf;
+ int rv;
if (recursion_level >= 20) {
file_error(ms, 0, "recursion nesting exceeded");
@@ -1620,16 +1624,34 @@ mget(struct magic_set *ms, const unsigned char *s,
break;
case FILE_INDIRECT:
- if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
- file_printf(ms, "%s", m->desc) == -1)
- return -1;
if (offset == 0)
return 0;
+
if (nbytes < offset)
- return 0;
- return file_softmagic(ms, s + offset, nbytes - offset,
+ return 0;
+
+ if ((pb = file_push_buffer(ms)) == NULL)
+ return -1;
+
+ rv = file_softmagic(ms, s + offset, nbytes - offset,
recursion_level, BINTEST, text);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
+
+ rbuf = file_pop_buffer(ms, pb);
+ if (rbuf == NULL && ms->event_flags & EVENT_HAD_ERR)
+ return -1;
+
+ if (rv == 1) {
+ if (file_printf(ms, "%s", rbuf) == -1) {
+ free(rbuf);
+ return -1;
+ }
+ }
+ free(rbuf);
+ return rv;
+
case FILE_DEFAULT: /* nothing to check */
default:
break;

34
SOURCES/file-5.11-CVE-2014-9652.patch

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
From 59e63838913eee47f5c120a6c53d4565af638158 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Tue, 11 Nov 2014 17:48:23 +0000
Subject: [PATCH] PR/398: Correctly truncate pascal strings (fixes out of
bounds read of 1, 2, or 4 bytes).

---
src/softmagic.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/softmagic.c b/src/softmagic.c
index dbb670a..2b15f2c 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -822,14 +822,17 @@ mconvert(struct magic_set *ms, struct magic *m)
size_t sz = file_pstring_length_size(m);
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
size_t len = file_pstring_get_length(m, ptr1);
- if (len >= sizeof(p->s)) {
+ sz = sizeof(p->s) - sz; /* maximum length of string */
+ if (len >= sz) {
/*
* The size of the pascal string length (sz)
* is 1, 2, or 4. We need at least 1 byte for NUL
* termination, but we've already truncated the
* string by p->s, so we need to deduct sz.
+ * Because we can use one of the bytes of the length
+ * after we shifted as NUL termination.
*/
- len = sizeof(p->s) - sz;
+ len = sz;
}
while (len--)
*ptr1++ = *ptr2++;

67
SOURCES/file-5.11-CVE-2014-9653.patch

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
diff --git a/src/readelf.c b/src/readelf.c
index 1f4d1f4..05ec736 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -327,7 +327,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* Loop through all the program headers.
*/
for ( ; num; num--) {
- if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
file_badread(ms);
return -1;
}
@@ -869,6 +869,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
char name[50];
+ ssize_t namesize;
if (size != xsh_sizeof) {
if (file_printf(ms, ", corrupted section header size") == -1)
@@ -877,7 +878,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
/* Read offset of name section to be able to read section names later */
- if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {
+ if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) {
file_badread(ms);
return -1;
}
@@ -885,15 +886,15 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
for ( ; num; num--) {
/* Read the name of this section. */
- if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {
+ if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) {
file_badread(ms);
return -1;
}
- name[sizeof(name) - 1] = '\0';
+ name[namesize] = '\0';
if (strcmp(name, ".debug_info") == 0)
stripped = 0;
- if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
+ if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
file_badread(ms);
return -1;
}
@@ -923,7 +924,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
" for note");
return -1;
}
- if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
+ if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {
file_badread(ms);
free(nbuf);
return -1;
@@ -1076,7 +1077,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
for ( ; num; num--) {
- if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
file_badread(ms);
return -1;
}

32
SOURCES/file-5.11-add-aarch64.patch

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
From a5c989d3d36e51293a0474c4653f595dcfb94751 Mon Sep 17 00:00:00 2001
From: Jeffrey Bastian <jbastian@redhat.com>
Date: Thu, 20 Feb 2014 15:45:42 -0500
Subject: [PATCH] add aarch64

backport of upstream https://github.com/glensc/file/commit/2dccf6a6615f
---
magic/Magdir/elf | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/magic/Magdir/elf b/magic/Magdir/elf
index 8e3b7bc..e0e9937 100644
--- a/magic/Magdir/elf
+++ b/magic/Magdir/elf
@@ -148,12 +148,11 @@
>>18 leshort 97 NatSemi 32k,
>>18 leshort 106 Analog Devices Blackfin,
>>18 leshort 113 Altera Nios II,
->>18 leshort 0xae META,
+>>18 leshort 174 META,
+>>18 leshort 183 ARM aarch64,
>>18 leshort 187 Tilera TILE64,
>>18 leshort 188 Tilera TILEPro,
>>18 leshort 191 Tilera TILE-Gx,
->>18 leshort 0x3426 OpenRISC (obsolete),
->>18 leshort 0x8472 OpenRISC (obsolete),
>>18 leshort 0x9026 Alpha (unofficial),
>>20 lelong 0 invalid version
>>20 lelong 1 version 1
--
1.8.3.1

564
SOURCES/file-5.11-auxv.patch

@ -0,0 +1,564 @@ @@ -0,0 +1,564 @@
diff --git a/src/readelf.c b/src/readelf.c
index 9651239..807affc 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -41,6 +41,8 @@ FILE_RCSID("@(#)$File: readelf.c,v 1.90 2011/08/23 08:01:12 christos Exp $")
#include "readelf.h"
#include "magic.h"
+#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
+
#ifdef ELFCORE
private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
off_t, int *);
@@ -50,7 +52,7 @@ private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
off_t, int *, int, int);
private size_t donote(struct magic_set *, void *, size_t, size_t, int,
- int, size_t, int *);
+ int, size_t, int *, int, off_t, int, off_t);
#define ELF_ALIGN(a) ((((a) + align - 1) / align) * align)
@@ -184,6 +186,11 @@ getu64(int swap, uint64_t value)
elf_getu32(swap, ph32.p_align) : 4) \
: (off_t) (ph64.p_align ? \
elf_getu64(swap, ph64.p_align) : 4)))
+#define xph_vaddr (size_t)((clazz == ELFCLASS32 \
+ ? (off_t) (ph32.p_vaddr ? \
+ elf_getu32(swap, ph32.p_vaddr) : 4) \
+ : (off_t) (ph64.p_vaddr ? \
+ elf_getu64(swap, ph64.p_vaddr) : 4)))
#define xph_filesz (size_t)((clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_filesz) \
: elf_getu64(swap, ph64.p_filesz)))
@@ -194,8 +201,8 @@ getu64(int swap, uint64_t value)
? elf_getu32(swap, ph32.p_memsz) \
: elf_getu64(swap, ph64.p_memsz)))
#define xnh_sizeof (clazz == ELFCLASS32 \
- ? sizeof nh32 \
- : sizeof nh64)
+ ? sizeof(nh32) \
+ : sizeof(nh64))
#define xnh_type (clazz == ELFCLASS32 \
? elf_getu32(swap, nh32.n_type) \
: elf_getu32(swap, nh64.n_type))
@@ -220,6 +227,18 @@ getu64(int swap, uint64_t value)
#define xcap_val (clazz == ELFCLASS32 \
? elf_getu32(swap, cap32.c_un.c_val) \
: elf_getu64(swap, cap64.c_un.c_val))
+#define xauxv_addr (clazz == ELFCLASS32 \
+ ? (void *)&auxv32 \
+ : (void *)&auxv64)
+#define xauxv_sizeof (clazz == ELFCLASS32 \
+ ? sizeof(auxv32) \
+ : sizeof(auxv64))
+#define xauxv_type (clazz == ELFCLASS32 \
+ ? elf_getu32(swap, auxv32.a_type) \
+ : elf_getu64(swap, auxv64.a_type))
+#define xauxv_val (clazz == ELFCLASS32 \
+ ? elf_getu32(swap, auxv32.a_v) \
+ : elf_getu64(swap, auxv64.a_v))
#ifdef ELFCORE
/*
@@ -306,6 +325,7 @@ private const char os_style_names[][8] = {
#define FLAGS_DID_BUILD_ID 0x04
#define FLAGS_DID_CORE_STYLE 0x08
#define FLAGS_IS_CORE 0x10
+#define FLAGS_DID_AUXV 0x200
private int
dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
@@ -316,6 +336,8 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
size_t offset, len;
unsigned char nbuf[BUFSIZ];
ssize_t bufsize;
+ off_t ph_off = off;
+ int ph_num = num;
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
@@ -355,7 +377,8 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
if (offset >= (size_t)bufsize)
break;
offset = donote(ms, nbuf, offset, (size_t)bufsize,
- clazz, swap, 4, flags);
+ clazz, swap, 4, flags, fd, ph_off,
+ ph_num, fsize);
if (offset == 0)
break;
@@ -365,9 +388,160 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
#endif
+private off_t
+get_offset_from_virtaddr(struct magic_set *ms, int swap, int clazz, int fd,
+ off_t off, int num, off_t fsize, uint64_t virtaddr)
+{
+ Elf32_Phdr ph32;
+ Elf64_Phdr ph64;
+
+ /*
+ * Loop through all the program headers and find the header with
+ * virtual address in which the "virtaddr" belongs to.
+ */
+ for ( ; num; num--) {
+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
+ file_badread(ms);
+ return -1;
+ }
+ off += xph_sizeof;
+
+ if (xph_offset > fsize) {
+ /* Perhaps warn here */
+ continue;
+ }
+
+ if (virtaddr >= xph_vaddr && virtaddr < xph_vaddr + xph_filesz)
+ return xph_offset + (virtaddr - xph_vaddr);
+ }
+ return 0;
+}
+
+private size_t
+get_string_on_virtaddr(struct magic_set *ms,
+ int swap, int clazz, int fd, off_t ph_off, int ph_num,
+ off_t fsize, uint64_t virtaddr, char *buf, ssize_t buflen)
+{
+ char *bptr;
+ off_t offset;
+
+ if (buflen == 0)
+ return 0;
+
+ offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num,
+ fsize, virtaddr);
+ if (offset < 0 || (buflen = pread(fd, buf, buflen, offset)) <= 0) {
+ file_badread(ms);
+ return 0;
+ }
+
+ buf[buflen - 1] = '\0';
+
+ /* We expect only printable characters, so return if buffer contains
+ * non-printable character before the '\0' or just '\0'. */
+ for (bptr = buf; *bptr && isprint((unsigned char)*bptr); bptr++)
+ continue;
+ if (*bptr != '\0')
+ return 0;
+
+ return bptr - buf;
+}
+
+
+private int
+do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
+ int swap, uint32_t namesz __attribute__((__unused__)),
+ uint32_t descsz __attribute__((__unused__)),
+ size_t noff __attribute__((__unused__)), size_t doff,
+ int *flags, size_t size __attribute__((__unused__)), int clazz,
+ int fd, off_t ph_off, int ph_num, off_t fsize)
+{
+#ifdef ELFCORE
+ Aux32Info auxv32;
+ Aux64Info auxv64;
+ size_t elsize = xauxv_sizeof;
+ const char *tag;
+ int is_string;
+ size_t nval;
+ size_t off;
+
+
+ if (type != NT_AUXV || (*flags & FLAGS_IS_CORE) == 0)
+ return 0;
+
+ *flags |= FLAGS_DID_AUXV;
+
+ nval = 0;
+ for (off = 0; off + elsize <= descsz; off += elsize) {
+ (void)memcpy(xauxv_addr, &nbuf[doff + off], xauxv_sizeof);
+ /* Limit processing to 50 vector entries to prevent DoS */
+ if (nval++ >= 50) {
+ file_error(ms, 0, "Too many ELF Auxv elements");
+ return 1;
+ }
+
+ switch(xauxv_type) {
+ case AT_LINUX_EXECFN:
+ is_string = 1;
+ tag = "execfn";
+ break;
+ case AT_LINUX_PLATFORM:
+ is_string = 1;
+ tag = "platform";
+ break;
+ case AT_LINUX_UID:
+ is_string = 0;
+ tag = "real uid";
+ break;
+ case AT_LINUX_GID:
+ is_string = 0;
+ tag = "real gid";
+ break;
+ case AT_LINUX_EUID:
+ is_string = 0;
+ tag = "effective uid";
+ break;
+ case AT_LINUX_EGID:
+ is_string = 0;
+ tag = "effective gid";
+ break;
+ default:
+ is_string = 0;
+ tag = NULL;
+ break;
+ }
+
+ if (tag == NULL)
+ continue;
+
+ if (is_string) {
+ char buf[256];
+ ssize_t buflen;
+ buflen = get_string_on_virtaddr(ms, swap, clazz, fd,
+ ph_off, ph_num, fsize, xauxv_val, buf, sizeof(buf));
+
+ if (buflen == 0)
+ continue;
+
+ if (file_printf(ms, ", %s: '%s'", tag, buf) == -1)
+ return 0;
+ } else {
+ if (file_printf(ms, ", %s: %d", tag, (int) xauxv_val)
+ == -1)
+ return 0;
+ }
+ }
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+
private size_t
donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
- int clazz, int swap, size_t align, int *flags)
+ int clazz, int swap, size_t align, int *flags,
+ int fd, off_t ph_off, int ph_num, off_t fsize)
{
Elf32_Nhdr nh32;
Elf64_Nhdr nh64;
@@ -390,6 +564,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
namesz = xnh_namesz;
descsz = xnh_descsz;
+
if ((namesz == 0) && (descsz == 0)) {
/*
* We're out of note headers.
@@ -438,37 +613,37 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
(void)memcpy(desc, &nbuf[doff], sizeof(desc));
if (file_printf(ms, ", for GNU/") == -1)
- return size;
+ return offset;
switch (elf_getu32(swap, desc[0])) {
case GNU_OS_LINUX:
if (file_printf(ms, "Linux") == -1)
- return size;
+ return offset;
break;
case GNU_OS_HURD:
if (file_printf(ms, "Hurd") == -1)
- return size;
+ return offset;
break;
case GNU_OS_SOLARIS:
if (file_printf(ms, "Solaris") == -1)
- return size;
+ return offset;
break;
case GNU_OS_KFREEBSD:
if (file_printf(ms, "kFreeBSD") == -1)
- return size;
+ return offset;
break;
case GNU_OS_KNETBSD:
if (file_printf(ms, "kNetBSD") == -1)
- return size;
+ return offset;
break;
default:
if (file_printf(ms, "<unknown>") == -1)
- return size;
+ return offset;
}
if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]),
elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1)
- return size;
+ return offset;
*flags |= FLAGS_DID_NOTE;
- return size;
+ return offset;
}
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
@@ -492,7 +667,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
desc = elf_getu32(swap, desc);
if (file_printf(ms, ", for NetBSD") == -1)
- return size;
+ return offset;
/*
* The version number used to be stuck as 199905, and was thus
* basically content-free. Newer versions of NetBSD have fixed
@@ -512,23 +687,23 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
uint32_t ver_maj = desc / 100000000;
if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
- return size;
+ return offset;
if (ver_rel == 0 && ver_patch != 0) {
if (file_printf(ms, ".%u", ver_patch) == -1)
- return size;
+ return offset;
} else if (ver_rel != 0) {
while (ver_rel > 26) {
if (file_printf(ms, "Z") == -1)
- return size;
+ return offset;
ver_rel -= 26;
}
if (file_printf(ms, "%c", 'A' + ver_rel - 1)
== -1)
- return size;
+ return offset;
}
}
*flags |= FLAGS_DID_NOTE;
- return size;
+ return offset;
}
if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0 &&
@@ -537,7 +712,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
desc = elf_getu32(swap, desc);
if (file_printf(ms, ", for FreeBSD") == -1)
- return size;
+ return offset;
/*
* Contents is __FreeBSD_version, whose relation to OS
@@ -567,69 +742,69 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
*/
if (desc == 460002) {
if (file_printf(ms, " 4.6.2") == -1)
- return size;
+ return offset;
} else if (desc < 460100) {
if (file_printf(ms, " %d.%d", desc / 100000,
desc / 10000 % 10) == -1)
- return size;
+ return offset;
if (desc / 1000 % 10 > 0)
if (file_printf(ms, ".%d", desc / 1000 % 10)
== -1)
- return size;
+ return offset;
if ((desc % 1000 > 0) || (desc % 100000 == 0))
if (file_printf(ms, " (%d)", desc) == -1)
- return size;
+ return offset;
} else if (desc < 500000) {
if (file_printf(ms, " %d.%d", desc / 100000,
desc / 10000 % 10 + desc / 1000 % 10) == -1)
- return size;
+ return offset;
if (desc / 100 % 10 > 0) {
if (file_printf(ms, " (%d)", desc) == -1)
- return size;
+ return offset;
} else if (desc / 10 % 10 > 0) {
if (file_printf(ms, ".%d", desc / 10 % 10)
== -1)
- return size;
+ return offset;
}
} else {
if (file_printf(ms, " %d.%d", desc / 100000,
desc / 1000 % 100) == -1)
- return size;
+ return offset;
if ((desc / 100 % 10 > 0) ||
(desc % 100000 / 100 == 0)) {
if (file_printf(ms, " (%d)", desc) == -1)
- return size;
+ return offset;
} else if (desc / 10 % 10 > 0) {
if (file_printf(ms, ".%d", desc / 10 % 10)
== -1)
- return size;
+ return offset;
}
}
*flags |= FLAGS_DID_NOTE;
- return size;
+ return offset;
}
if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 &&
xnh_type == NT_OPENBSD_VERSION && descsz == 4) {
if (file_printf(ms, ", for OpenBSD") == -1)
- return size;
+ return offset;
/* Content of note is always 0 */
*flags |= FLAGS_DID_NOTE;
- return size;
+ return offset;
}
if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 &&
xnh_type == NT_DRAGONFLY_VERSION && descsz == 4) {
uint32_t desc;
if (file_printf(ms, ", for DragonFly") == -1)
- return size;
+ return offset;
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
desc = elf_getu32(swap, desc);
if (file_printf(ms, " %d.%d.%d", desc / 100000,
desc / 10000 % 10, desc % 10000) == -1)
- return size;
+ return offset;
*flags |= FLAGS_DID_NOTE;
- return size;
+ return offset;
}
core:
@@ -661,14 +836,22 @@ core:
os_style = OS_STYLE_NETBSD;
}
+ if ((*flags & FLAGS_DID_AUXV) == 0) {
+ if (do_auxv_note(ms, nbuf, xnh_type, swap,
+ namesz, descsz, noff, doff, flags, size, clazz,
+ fd, ph_off, ph_num, fsize))
+ return offset;
+ }
+
+
#ifdef ELFCORE
if ((*flags & FLAGS_DID_CORE) != 0)
- return size;
+ return offset;
if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {
if (file_printf(ms, ", %s-style", os_style_names[os_style])
== -1)
- return size;
+ return offset;
*flags |= FLAGS_DID_CORE_STYLE;
}
@@ -683,7 +866,7 @@ core:
*/
if (file_printf(ms, ", from '%.31s'",
&nbuf[doff + 0x7c]) == -1)
- return size;
+ return offset;
/*
* Extract the signal number. It is at
@@ -693,9 +876,9 @@ core:
sizeof(signo));
if (file_printf(ms, " (signal %u)",
elf_getu32(swap, signo)) == -1)
- return size;
+ return offset;
*flags |= FLAGS_DID_CORE;
- return size;
+ return offset;
}
break;
@@ -793,9 +976,9 @@ core:
cp--;
if (file_printf(ms, ", from '%.*s'",
(int)(cp - cname), cname) == -1)
- return size;
+ return offset;
*flags |= FLAGS_DID_CORE;
- return size;
+ return offset;
tryanother:
;
@@ -936,7 +1119,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
if (noff >= (off_t)xsh_size)
break;
noff = donote(ms, nbuf, (size_t)noff,
- xsh_size, clazz, swap, 4, flags);
+ xsh_size, clazz, swap, 4, flags, 0, 0, 0, 0);
if (noff == 0)
break;
}
@@ -1130,7 +1313,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
break;
offset = donote(ms, nbuf, offset,
(size_t)bufsize, clazz, swap, align,
- flags);
+ flags, 0, 0, 0, 0);
if (offset == 0)
break;
}
diff --git a/src/readelf.h b/src/readelf.h
index ab4b5d1..fb34585 100644
--- a/src/readelf.h
+++ b/src/readelf.h
@@ -62,6 +62,42 @@ typedef uint8_t Elf64_Char;
#define EI_NIDENT 16
typedef struct {
+ Elf32_Word a_type; /* 32-bit id */
+ Elf32_Word a_v; /* 32-bit id */
+} Aux32Info;
+
+typedef struct {
+ Elf64_Xword a_type; /* 64-bit id */
+ Elf64_Xword a_v; /* 64-bit id */
+} Aux64Info;
+
+#define AT_NULL 0 /* end of vector */
+#define AT_IGNORE 1 /* entry should be ignored */
+#define AT_EXECFD 2 /* file descriptor of program */
+#define AT_PHDR 3 /* program headers for program */
+#define AT_PHENT 4 /* size of program header entry */
+#define AT_PHNUM 5 /* number of program headers */
+#define AT_PAGESZ 6 /* system page size */
+#define AT_BASE 7 /* base address of interpreter */
+#define AT_FLAGS 8 /* flags */
+#define AT_ENTRY 9 /* entry point of program */
+#define AT_LINUX_NOTELF 10 /* program is not ELF */
+#define AT_LINUX_UID 11 /* real uid */
+#define AT_LINUX_EUID 12 /* effective uid */
+#define AT_LINUX_GID 13 /* real gid */
+#define AT_LINUX_EGID 14 /* effective gid */
+#define AT_LINUX_PLATFORM 15 /* string identifying CPU for optimizations */
+#define AT_LINUX_HWCAP 16 /* arch dependent hints at CPU capabilities */
+#define AT_LINUX_CLKTCK 17 /* frequency at which times() increments */
+/* AT_* values 18 through 22 are reserved */
+#define AT_LINUX_SECURE 23 /* secure mode boolean */
+#define AT_LINUX_BASE_PLATFORM 24 /* string identifying real platform, may
+ * differ from AT_PLATFORM. */
+#define AT_LINUX_RANDOM 25 /* address of 16 random bytes */
+#define AT_LINUX_HWCAP2 26 /* extension of AT_HWCAP */
+#define AT_LINUX_EXECFN 31 /* filename of program */
+
+typedef struct {
Elf32_Char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;

32
SOURCES/file-5.11-buildid.patch

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
From 26f146f7dcf96f8f0a5b2f0503bdb4c46b74cf56 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Wed, 31 Oct 2012 17:03:41 +0000
Subject: [PATCH] PR/208: Fix buildid format

---
src/readelf.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index deb6d31..158f789 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -473,13 +473,14 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
xnh_type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {
- uint32_t desc[5], i;
- if (file_printf(ms, ", BuildID[%s]=0x", descsz == 16 ? "md5/uuid" :
+ uint8_t desc[20];
+ uint32_t i;
+ if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :
"sha1") == -1)
return size;
(void)memcpy(desc, &nbuf[doff], descsz);
- for (i = 0; i < descsz >> 2; i++)
- if (file_printf(ms, "%.8x", desc[i]) == -1)
+ for (i = 0; i < descsz; i++)
+ if (file_printf(ms, "%02x", desc[i]) == -1)
return size;
*flags |= FLAGS_DID_BUILD_ID;
}

13
SOURCES/file-5.11-compress.patch

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
diff --git a/src/compress.c b/src/compress.c
index 2b05352..ccb1cfd 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -183,7 +183,7 @@ sread(int fd, void *buf, size_t n, int canbepipe __attribute__ ((unused)))
goto nocheck;
#ifdef FIONREAD
- if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) {
+ if (canbepipe && ((ioctl(fd, FIONREAD, &t) == -1) || (t == 0))) {
#ifdef FD_ZERO
for (cnt = 0;; cnt++) {
fd_set check;

13
SOURCES/file-5.11-dump-twice.patch

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
diff --git a/magic/Magdir/convex b/magic/Magdir/convex
index 6141a82..4e096b9 100644
--- a/magic/Magdir/convex
+++ b/magic/Magdir/convex
@@ -30,8 +30,6 @@
# The restore program uses these number to determine how the data is
# to be extracted.
#
-24 belong =60011 dump format, 4.1 BSD or earlier
-24 belong =60012 dump format, 4.2 or 4.3 BSD without IDC
24 belong =60013 dump format, 4.2 or 4.3 BSD (IDC compatible)
24 belong =60014 dump format, Convex Storage Manager by-reference dump
#

56
SOURCES/file-5.11-exit-code.patch

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
diff --git a/src/fsmagic.c b/src/fsmagic.c
index 7200271..1ffe667 100644
--- a/src/fsmagic.c
+++ b/src/fsmagic.c
@@ -124,14 +124,12 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
if (ret) {
if (ms->flags & MAGIC_ERROR) {
- file_error(ms, errno, "cannot stat `%s'", fn);
+ file_error(ms, errno, "cannot stat");
return -1;
}
- if (file_printf(ms, "cannot open `%s' (%s)",
- fn, strerror(errno)) == -1)
+ if (file_printf(ms, "cannot open (%s)", strerror(errno)) == -1)
return -1;
- ms->event_flags |= EVENT_HAD_ERR;
- return -1;
+ return 0;
}
if (!mime) {
diff --git a/src/magic.c b/src/magic.c
index 2b61080..a184a35 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -417,8 +417,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
ispipe = 1;
} else {
int flags = O_RDONLY|O_BINARY;
+ int okstat = stat(inname, &sb) == 0;
- if (stat(inname, &sb) == 0 && S_ISFIFO(sb.st_mode)) {
+ if (okstat && S_ISFIFO(sb.st_mode)) {
#ifdef O_NONBLOCK
flags |= O_NONBLOCK;
#endif
@@ -427,7 +428,8 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
errno = 0;
if ((fd = open(inname, flags)) < 0) {
- if (unreadable_info(ms, sb.st_mode, inname) == -1)
+ if (okstat &&
+ unreadable_info(ms, sb.st_mode, inname) == -1)
goto done;
rv = 0;
goto done;
@@ -462,7 +464,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
} else {
if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
- file_error(ms, errno, "cannot read `%s'", inname);
+ file_error(ms, errno, "cannot read");
goto done;
}
}

30
SOURCES/file-5.11-gzip-strength.patch

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
From af069cb735df84c45b9ab06a789eb9fd89bee38d Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Wed, 11 Dec 2013 17:55:00 +0000
Subject: [PATCH] Bump the strength of gzip and reorder printing of attributes
(Thomas Ledoux)

Upstream-commit: 5c945517d8b4e4c7db9f132f04fa4814dc957a83

Rordering of attributes dropped from this patch to stay compatible.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/compress | 1 +
1 file changed, 1 insertion(+)

diff --git a/magic/Magdir/compress b/magic/Magdir/compress
index 94c209d..5dc4dcf 100644
--- a/magic/Magdir/compress
+++ b/magic/Magdir/compress
@@ -22,6 +22,7 @@
# other than 8 ("deflate", the only method defined in RFC 1952).
0 string \037\213 gzip compressed data
!:mime application/x-gzip
+!:strength * 2
>2 byte <8 \b, reserved method
>2 byte >8 \b, unknown method
>3 byte &0x01 \b, ASCII
--
2.13.5

12
SOURCES/file-5.11-ia64-swap.patch

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
diff --git a/magic/Magdir/linux b/magic/Magdir/linux
index 8d4c60a..aa8d1aa 100644
--- a/magic/Magdir/linux
+++ b/magic/Magdir/linux
@@ -88,6 +88,7 @@
# From Daniel Novotny <dnovotny@redhat.com>
# swap file for PowerPC
65526 string SWAPSPACE2 Linux/ppc swap file
+16374 string SWAPSPACE2 Linux/ia64 swap file
#
# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>
# and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>

13
SOURCES/file-5.11-java1718.patch

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
diff --git a/magic/Magdir/cafebabe b/magic/Magdir/cafebabe
index 6400e2f..6f2e96d 100644
--- a/magic/Magdir/cafebabe
+++ b/magic/Magdir/cafebabe
@@ -27,6 +27,8 @@
>>4 belong 0x0030 (Java 1.4)
>>4 belong 0x0031 (Java 1.5)
>>4 belong 0x0032 (Java 1.6)
+>>4 belong 0x0033 (Java 1.7)
+>>4 belong 0x0034 (Java 1.8)
0 belong 0xcafebabe

32
SOURCES/file-5.11-magicmgc-home.patch

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
diff --git a/src/magic.c b/src/magic.c
index 5403951..2b61080 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -101,16 +101,21 @@ get_default_magic(void)
if ((home = getenv("HOME")) == NULL)
return MAGIC;
- if (asprintf(&hmagicpath, "%s/.magic", home) < 0)
+ if (asprintf(&hmagicpath, "%s/.magic.mgc", home) < 0)
return MAGIC;
- if (stat(hmagicpath, &st) == -1)
- goto out;
- if (S_ISDIR(st.st_mode)) {
+ if (stat(hmagicpath, &st) == -1) {
free(hmagicpath);
- if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0)
+ if (asprintf(&hmagicpath, "%s/.magic", home) < 0)
return MAGIC;
- if (access(hmagicpath, R_OK) == -1)
+ if (stat(hmagicpath, &st) == -1)
goto out;
+ if (S_ISDIR(st.st_mode)) {
+ free(hmagicpath);
+ if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0)
+ return MAGIC;
+ if (access(hmagicpath, R_OK) == -1)
+ goto out;
+ }
}
if (asprintf(&default_magic, "%s:%s", hmagicpath, MAGIC) < 0)

14
SOURCES/file-5.11-newpython.patch

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
diff --git a/magic/Magdir/python b/magic/Magdir/python
index 23f8d6b..6d7121a 100644
--- a/magic/Magdir/python
+++ b/magic/Magdir/python
@@ -22,6 +22,9 @@
0 belong 0x3b0c0d0a python 3.0 byte-compiled
0 belong 0x4f0c0d0a python 3.1 byte-compiled
0 belong 0x6c0c0d0a python 3.2 byte-compiled
+0 belong 0x9e0c0d0a python 3.3 byte-compiled
+0 belong 0xee0c0d0a python 3.4 byte-compiled
+0 belong 0x160d0d0a python 3.5 byte-compiled
0 search/1/w #!\ /usr/bin/python Python script text executable
!:mime text/x-python

31
SOURCES/file-5.11-offset-oob.patch

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
diff --git a/src/softmagic.c b/src/softmagic.c
index 8d08cad..6dc86f5 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -41,8 +41,6 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.147 2011/11/05 15:44:22 rrt Exp $")
#include <stdlib.h>
#include <time.h>
-#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) >= ((n) - (o)))
-
private int match(struct magic_set *, struct magic *, uint32_t,
const unsigned char *, size_t, int, int, int);
private int mget(struct magic_set *, const unsigned char *,
@@ -1601,7 +1599,7 @@ mget(struct magic_set *ms, const unsigned char *s,
break;
case FILE_REGEX:
- if (OFFSET_OOB(nbytes, offset, 0))
+ if (nbytes < offset)
return 0;
break;
@@ -1611,7 +1609,7 @@ mget(struct magic_set *ms, const unsigned char *s,
return -1;
if (offset == 0)
return 0;
- if (OFFSET_OOB(nbytes, offset, 0))
+ if (nbytes < offset)
return 0;
return file_softmagic(ms, s + offset, nbytes - offset,
recursion_level, BINTEST, text);

16
SOURCES/file-5.11-pascal.patch

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
diff --git a/magic/Magdir/pascal b/magic/Magdir/pascal
index a134a47..d8e61c6 100644
--- a/magic/Magdir/pascal
+++ b/magic/Magdir/pascal
@@ -4,7 +4,7 @@
#
0 search/8192 (input, Pascal source text
!:mime text/x-pascal
-0 regex \^program Pascal source text
-!:mime text/x-pascal
-0 regex \^record Pascal source text
-!:mime text/x-pascal
+#0 regex \^program Pascal source text
+#!:mime text/x-pascal
+#0 regex \^record Pascal source text
+#!:mime text/x-pascal

37
SOURCES/file-5.11-perl-shebang.patch

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
diff --git a/magic/Magdir/perl b/magic/Magdir/perl
index ef0cc6d..453665c 100644
--- a/magic/Magdir/perl
+++ b/magic/Magdir/perl
@@ -5,24 +5,22 @@
# The `eval' lines recognizes an outrageously clever hack.
# Keith Waclena <keith@cerberus.uchicago.edu>
# Send additions to <perl5-porters@perl.org>
-0 search/1/w #!\ /bin/perl Perl script text executable
-!:mime text/x-perl
0 search/1 eval\ "exec\ /bin/perl Perl script text
!:mime text/x-perl
-0 search/1/w #!\ /usr/bin/perl Perl script text executable
-!:mime text/x-perl
0 search/1 eval\ "exec\ /usr/bin/perl Perl script text
!:mime text/x-perl
-0 search/1/w #!\ /usr/local/bin/perl Perl script text executable
-!:mime text/x-perl
0 search/1 eval\ "exec\ /usr/local/bin/perl Perl script text
!:mime text/x-perl
0 search/1 eval\ '(exit\ $?0)'\ &&\ eval\ 'exec Perl script text
!:mime text/x-perl
-0 search/1 #!/usr/bin/env\ perl Perl script text executable
-!:mime text/x-perl
-0 search/1 #!\ /usr/bin/env\ perl Perl script text executable
-!:mime text/x-perl
+
+0 search/1 #!
+>0 regex \^#!.*/bin/perl.*$ Perl script text executable
+!:mime text/x-perl
+>0 regex \^#!.*/bin/env\ perl.*$ Perl script text executable
+!:mime text/x-perl
+# to be tried before awk script
+!:strength + 40
# by Dmitry V. Levin and Alexey Tourbin
# check the first line

29
SOURCES/file-5.11-ppc64.patch

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
diff --git a/magic/Magdir/elf b/magic/Magdir/elf
index e0e9937..11c876e 100644
--- a/magic/Magdir/elf
+++ b/magic/Magdir/elf
@@ -84,10 +84,21 @@
>>>48 leshort &0x0008 (LP64),
>>18 leshort 16 nCUBE,
>>18 leshort 17 Fujitsu VPP500,
->>18 leshort 18 SPARC32PLUS - invalid byte order,
->>18 leshort 20 PowerPC,
+>>18 leshort 18 SPARC32PLUS,
+# only for 32-bit
+>>>4 byte 1
+>>>>36 lelong&0xffff00 0x000100 V8+ Required,
+>>>>36 lelong&0xffff00 0x000200 Sun UltraSPARC1 Extensions Required,
+>>>>36 lelong&0xffff00 0x000400 HaL R1 Extensions Required,
+>>>>36 lelong&0xffff00 0x000800 Sun UltraSPARC3 Extensions Required,
+>>18 leshort 19 Intel 80960,
+>>18 leshort 20 PowerPC or cisco 4500,
+>>18 leshort 21 64-bit PowerPC or cisco 7500,
>>18 leshort 22 IBM S/390,
->>18 leshort 36 NEC V800,
+>>18 leshort 23 Cell SPU,
+>>18 leshort 24 cisco SVIP,
+>>18 leshort 25 cisco 7200,
+>>18 leshort 36 NEC V800 or cisco 12000,
>>18 leshort 37 Fujitsu FR20,
>>18 leshort 38 TRW RH-32,
>>18 leshort 39 Motorola RCE,

39
SOURCES/file-5.11-python-comment.patch

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
From ac2eb47fe154aa01460414de987491b02ea225e2 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Sat, 15 Feb 2014 01:30:52 +0000
Subject: [PATCH] comment out python comment magic cause other things like
mediawiki use it.

Upstream-commit: eced9dbd4aa438de22ff453c723136beac41a558
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/python | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/magic/Magdir/python b/magic/Magdir/python
index 53cae42..b3ee014 100644
--- a/magic/Magdir/python
+++ b/magic/Magdir/python
@@ -46,13 +46,13 @@
!:mime text/x-python
# comments
-0 search/4096 '''
->&0 regex .*'''$ Python script text executable
-!:mime text/x-python
+#0 search/4096 '''
+#>&0 regex .*'''$ Python script text executable
+#!:mime text/x-python
-0 search/4096 """
->&0 regex .*"""$ Python script text executable
-!:mime text/x-python
+#0 search/4096 """
+#>&0 regex .*"""$ Python script text executable
+#!:mime text/x-python
# try:
# except: or finally:
--
2.14.4

26
SOURCES/file-5.11-qcow3.patch

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
diff --git a/magic/Magdir/msdos b/magic/Magdir/msdos
index 8f3e532..21f055d 100644
--- a/magic/Magdir/msdos
+++ b/magic/Magdir/msdos
@@ -811,6 +811,21 @@
>>24 bequad x \b, %lld bytes
>>32 belong 1 \b, AES-encrypted
+>4 belong 3 (v3)
+# Using the existence of the Backing File Offset to determine whether
+# to read Backing File Information
+>>8 bequad >0 \b, has backing file
+# Note that this isn't a null-terminated string; the length is actually
+# (16.L). Assuming a null-terminated string happens to work usually, but it
+# may spew junk until it reaches a \0 in some cases. Also, since there's no
+# .Q modifier, we just use the bottom four bytes as an offset. Note that if
+# the file is over 4G, and the backing file path is stored after the first 4G,
+# the wrong filename will be printed. (This should be (8.Q), when that syntax
+# is introduced.)
+>>>(12.L) string >\0 (path %s)
+>>24 bequad x \b, %lld bytes
+>>32 belong 1 \b, AES-encrypted
+
>4 default x (unknown version)
0 string/b QEVM QEMU suspend to disk image

15
SOURCES/file-5.11-rrdtool.patch

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
diff --git a/magic/Magdir/database b/magic/Magdir/database
index 5c38f5c..a17cc42 100644
--- a/magic/Magdir/database
+++ b/magic/Magdir/database
@@ -84,8 +84,8 @@
#
#
# Round Robin Database Tool by Tobias Oetiker <oetiker@ee.ethz.ch>
-0 string RRD RRDTool DB
->4 string x version %s
+0 string/b RRD\0 RRDTool DB
+>4 string/b x version %s
#----------------------------------------------------------------------
# ROOT: file(1) magic for ROOT databases
#

17
SOURCES/file-5.11-softmagic-read.patch

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
diff --git a/src/softmagic.c b/src/softmagic.c
index 8d08cad..8262788 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -199,9 +199,9 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
if (file_check_mem(ms, ++cont_level) == -1)
return -1;
- while (magic[magindex+1].cont_level != 0 &&
- ++magindex < nmagic) {
- m = &magic[magindex];
+ while (magindex + 1 < nmagic &&
+ magic[magindex + 1].cont_level != 0) {
+ m = &magic[++magindex];
ms->line = m->lineno; /* for messages */
if (cont_level < m->cont_level)

318
SOURCES/file-5.11-stripped.patch

@ -0,0 +1,318 @@ @@ -0,0 +1,318 @@
diff --git a/configure.ac b/configure.ac
index 1511c9a..97a4689 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,7 +159,7 @@ dnl Checks for functions
AC_CHECK_FUNCS(mmap strerror strndup strtoul mbrtowc mkstemp utimes utime wcwidth strtof fork)
dnl Provide implementation of some required functions if necessary
-AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline)
+AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline pread)
dnl Checks for libraries
AC_CHECK_LIB(z,gzopen)
diff --git a/src/cdf.c b/src/cdf.c
index d05d279..3b2b79b 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.50 2012/02/20 22:35:29 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.51 2012/03/20 18:28:02 christos Exp $")
#endif
#include <assert.h>
@@ -296,10 +296,7 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
if (info->i_fd == -1)
return -1;
- if (lseek(info->i_fd, off, SEEK_SET) == (off_t)-1)
- return -1;
-
- if (read(info->i_fd, buf, len) != (ssize_t)len)
+ if (pread(info->i_fd, buf, len, off) != (ssize_t)len)
return -1;
return (ssize_t)len;
diff --git a/src/elfclass.h b/src/elfclass.h
index 2e7741b..010958a 100644
--- a/src/elfclass.h
+++ b/src/elfclass.h
@@ -59,7 +59,8 @@
(off_t)elf_getu(swap, elfhdr.e_shoff),
elf_getu16(swap, elfhdr.e_shnum),
(size_t)elf_getu16(swap, elfhdr.e_shentsize),
- fsize, &flags, elf_getu16(swap, elfhdr.e_machine)) == -1)
+ fsize, &flags, elf_getu16(swap, elfhdr.e_machine),
+ (int)elf_getu16(swap, elfhdr.e_shstrndx)) == -1)
return -1;
break;
diff --git a/src/file.h b/src/file.h
index 1b5f53f..28f9bc7 100644
--- a/src/file.h
+++ b/src/file.h
@@ -462,6 +462,9 @@ extern char *sys_errlist[];
#define strtoul(a, b, c) strtol(a, b, c)
#endif
+#ifndef HAVE_PREAD
+ssize_t pread(int, void *, size_t, off_t);
+#endif
#ifndef HAVE_VASPRINTF
int vasprintf(char **, const char *, va_list);
#endif
diff --git a/src/readelf.c b/src/readelf.c
index ce4832a..8d355c5 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -48,7 +48,7 @@ private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
off_t, int *, int);
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
- off_t, int *, int);
+ off_t, int *, int, int);
private size_t donote(struct magic_set *, void *, size_t, size_t, int,
int, size_t, int *);
@@ -129,19 +129,21 @@ getu64(int swap, uint64_t value)
#define elf_getu32(swap, value) getu32(swap, value)
#ifdef USE_ARRAY_FOR_64BIT_TYPES
# define elf_getu64(swap, array) \
- ((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 : elf_getu32(swap, array[0])) + \
- (swap ? elf_getu32(swap, array[1]) : ((uint64_t)elf_getu32(swap, array[1]) << 32)))
+ ((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 \
+ : elf_getu32(swap, array[0])) + \
+ (swap ? elf_getu32(swap, array[1]) : \
+ ((uint64_t)elf_getu32(swap, array[1]) << 32)))
#else
# define elf_getu64(swap, value) getu64(swap, value)
#endif
#define xsh_addr (clazz == ELFCLASS32 \
- ? (void *) &sh32 \
- : (void *) &sh64)
+ ? (void *)&sh32 \
+ : (void *)&sh64)
#define xsh_sizeof (clazz == ELFCLASS32 \
- ? sizeof sh32 \
- : sizeof sh64)
-#define xsh_size (clazz == ELFCLASS32 \
+ ? sizeof(sh32) \
+ : sizeof(sh64))
+#define xsh_size (size_t)(clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_size) \
: elf_getu64(swap, sh64.sh_size))
#define xsh_offset (off_t)(clazz == ELFCLASS32 \
@@ -150,12 +152,15 @@ getu64(int swap, uint64_t value)
#define xsh_type (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_type) \
: elf_getu32(swap, sh64.sh_type))
+#define xsh_name (clazz == ELFCLASS32 \
+ ? elf_getu32(swap, sh32.sh_name) \
+ : elf_getu32(swap, sh64.sh_name))
#define xph_addr (clazz == ELFCLASS32 \
? (void *) &ph32 \
: (void *) &ph64)
#define xph_sizeof (clazz == ELFCLASS32 \
- ? sizeof ph32 \
- : sizeof ph64)
+ ? sizeof(ph32) \
+ : sizeof(ph64))
#define xph_type (clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_type) \
: elf_getu32(swap, ph64.p_type))
@@ -171,8 +176,8 @@ getu64(int swap, uint64_t value)
? elf_getu32(swap, ph32.p_filesz) \
: elf_getu64(swap, ph64.p_filesz)))
#define xnh_addr (clazz == ELFCLASS32 \
- ? (void *) &nh32 \
- : (void *) &nh64)
+ ? (void *)&nh32 \
+ : (void *)&nh64)
#define xph_memsz (size_t)((clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_memsz) \
: elf_getu64(swap, ph64.p_memsz)))
@@ -192,8 +197,8 @@ getu64(int swap, uint64_t value)
? prpsoffsets32[i] \
: prpsoffsets64[i])
#define xcap_addr (clazz == ELFCLASS32 \
- ? (void *) &cap32 \
- : (void *) &cap64)
+ ? (void *)&cap32 \
+ : (void *)&cap64)
#define xcap_sizeof (clazz == ELFCLASS32 \
? sizeof cap32 \
: sizeof cap64)
@@ -296,7 +301,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
- size_t offset;
+ size_t offset, len;
unsigned char nbuf[BUFSIZ];
ssize_t bufsize;
@@ -310,11 +315,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* Loop through all the program headers.
*/
for ( ; num; num--) {
- if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
- file_badseek(ms);
- return -1;
- }
- if (read(fd, xph_addr, xph_sizeof) == -1) {
+ if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
file_badread(ms);
return -1;
}
@@ -332,13 +333,8 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
- if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
- file_badseek(ms);
- return -1;
- }
- bufsize = read(fd, nbuf,
- ((xph_filesz < sizeof(nbuf)) ? xph_filesz : sizeof(nbuf)));
- if (bufsize == -1) {
+ len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf);
+ if ((bufsize = pread(fd, nbuf, len, xph_offset)) == -1) {
file_badread(ms);
return -1;
}
@@ -843,15 +839,16 @@ static const cap_desc_t cap_desc_386[] = {
private int
doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
- size_t size, off_t fsize, int *flags, int mach)
+ size_t size, off_t fsize, int *flags, int mach, int strtab)
{
Elf32_Shdr sh32;
Elf64_Shdr sh64;
int stripped = 1;
void *nbuf;
- off_t noff, coff;
+ off_t noff, coff, name_off;
uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
+ char name[50];
if (size != xsh_sizeof) {
if (file_printf(ms, ", corrupted section header size") == -1)
@@ -859,12 +856,24 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
return 0;
}
+ /* Read offset of name section to be able to read section names later */
+ if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {
+ file_badread(ms);
+ return -1;
+ }
+ name_off = xsh_offset;
+
for ( ; num; num--) {
- if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
- file_badseek(ms);
+ /* Read the name of this section. */
+ if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {
+ file_badread(ms);
return -1;
}
- if (read(fd, xsh_addr, xsh_sizeof) == -1) {
+ name[sizeof(name) - 1] = '\0';
+ if (strcmp(name, ".debug_info") == 0)
+ stripped = 0;
+
+ if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
file_badread(ms);
return -1;
}
@@ -889,39 +898,30 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
/* Things we can determine when we seek */
switch (xsh_type) {
case SHT_NOTE:
- if ((nbuf = malloc((size_t)xsh_size)) == NULL) {
+ if ((nbuf = malloc(xsh_size)) == NULL) {
file_error(ms, errno, "Cannot allocate memory"
" for note");
return -1;
}
- if ((noff = lseek(fd, (off_t)xsh_offset, SEEK_SET)) ==
- (off_t)-1) {
+ if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
file_badread(ms);
free(nbuf);
return -1;
}
- if (read(fd, nbuf, (size_t)xsh_size) !=
- (ssize_t)xsh_size) {
- free(nbuf);
- file_badread(ms);
- return -1;
- }
noff = 0;
for (;;) {
if (noff >= (off_t)xsh_size)
break;
noff = donote(ms, nbuf, (size_t)noff,
- (size_t)xsh_size, clazz, swap, 4,
- flags);
+ xsh_size, clazz, swap, 4, flags);
if (noff == 0)
break;
}
free(nbuf);
break;
case SHT_SUNW_cap:
- if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
- (off_t)-1) {
+ if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
@@ -1043,7 +1043,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
const char *shared_libraries = "";
unsigned char nbuf[BUFSIZ];
ssize_t bufsize;
- size_t offset, align;
+ size_t offset, align, len;
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
@@ -1052,13 +1052,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
for ( ; num; num--) {
- if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
- file_badseek(ms);
- return -1;
- }
-
- if (read(fd, xph_addr, xph_sizeof) == -1) {
- file_badread(ms);
+ if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
+ file_badread(ms);
return -1;
}
@@ -1096,12 +1091,9 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
- if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
- file_badseek(ms);
- return -1;
- }
- bufsize = read(fd, nbuf, ((xph_filesz < sizeof(nbuf)) ?
- xph_filesz : sizeof(nbuf)));
+ len = xph_filesz < sizeof(nbuf) ? xph_filesz
+ : sizeof(nbuf);
+ bufsize = pread(fd, nbuf, len, xph_offset);
if (bufsize == -1) {
file_badread(ms);
return -1;

23
SOURCES/file-5.11-swap-info.patch

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
diff --git a/magic/Magdir/linux b/magic/Magdir/linux
index aa8d1aa..90f0f46 100644
--- a/magic/Magdir/linux
+++ b/magic/Magdir/linux
@@ -87,7 +87,17 @@
>0x41a beshort x \b%04x
# From Daniel Novotny <dnovotny@redhat.com>
# swap file for PowerPC
-65526 string SWAPSPACE2 Linux/ppc swap file
+65526 string SWAPSPACE2 Linux swap file
+>0x400 long x version %d,
+>0x404 long x size %d pages,
+>1052 string \0 no label,
+>1052 string >\0 LABEL=%s,
+>0x40c belong x UUID=%08x
+>0x410 beshort x \b-%04x
+>0x412 beshort x \b-%04x
+>0x414 beshort x \b-%04x
+>0x416 belong x \b-%08x
+>0x41a beshort x \b%04x
16374 string SWAPSPACE2 Linux/ia64 swap file
#
# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>

27
SOURCES/file-5.11-version.patch

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
From 5c9813d05317379b38e04b1b7ffb8cca6a236143 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Thu, 6 Sep 2012 14:18:50 +0000
Subject: [PATCH] PR/198: Version should not exit 1

Upstream-commit: a5a197f98d6ad293a25f3e20563aab31906c5ab3
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/file.c b/src/file.c
index 408ec63..7911b07 100644
--- a/src/file.c
+++ b/src/file.c
@@ -252,7 +252,7 @@ main(int argc, char *argv[])
(void)fprintf(stdout, "%s-%s\n", progname, VERSION);
(void)fprintf(stdout, "magic file from %s\n",
magicfile);
- return 1;
+ return 0;
case 'z':
flags |= MAGIC_COMPRESS;
break;
--
2.5.5

47
SOURCES/file-5.11-xml.patch

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
diff --git a/magic/Magdir/sgml b/magic/Magdir/sgml
index 3f78c2f..991f90d 100644
--- a/magic/Magdir/sgml
+++ b/magic/Magdir/sgml
@@ -17,16 +17,16 @@
# xhtml
0 string/t \<?xml\ version="
->15 string >\0
->>19 search/4096/cWbt \<!doctype\ html XHTML document text
+>19 search/4096/cWbt \<!doctype\ html XHTML document text
+>>15 string >\0 (version %.3s)
!:mime text/html
0 string/t \<?xml\ version='
->15 string >\0
->>19 search/4096/cWbt \<!doctype\ html XHTML document text
+>19 search/4096/cWbt \<!doctype\ html XHTML document text
+>>15 string >\0 (version %.3s)
!:mime text/html
0 string/t \<?xml\ version="
->15 string >\0
->>19 search/4096/cWbt \<html broken XHTML document text
+>19 search/4096/cWbt \<html broken XHTML document text
+>>15 string >\0 (version %.3s)
!:mime text/html
#------------------------------------------------------------------------------
@@ -59,17 +59,14 @@
!:mime application/xml
0 string/t \<?xml\ version=" XML
!:mime application/xml
->15 search/1 >\0 %.3s document text
+>15 string/t >\0 %.3s document text
>>23 search/1 \<xsl:stylesheet (XSL stylesheet)
>>24 search/1 \<xsl:stylesheet (XSL stylesheet)
0 string \<?xml\ version=' XML
!:mime application/xml
->15 search/1 >\0 %.3s document text
+>15 string/t >\0 %.3s document text
>>23 search/1 \<xsl:stylesheet (XSL stylesheet)
>>24 search/1 \<xsl:stylesheet (XSL stylesheet)
-0 search/1/wbt \<?xml XML document text
-!:mime application/xml
-!:strength - 10
0 search/1/wt \<?XML broken XML document text
!:mime application/xml
!:strength - 10

52
SOURCES/file-5.14-netpbm.patch

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
diff --git a/magic/Magdir/images b/magic/Magdir/images
index e94905c..a25d292 100644
--- a/magic/Magdir/images
+++ b/magic/Magdir/images
@@ -32,17 +32,42 @@
# PBMPLUS images
# The next byte following the magic is always whitespace.
-0 search/1 P1 Netpbm PBM image text
+# strength is changed to try these patterns before "x86 boot sector"
+0 search/1 P1
+>3 regex =[0-9]*\ [0-9]* Netpbm PBM image text
+>3 regex =[0-9]+\ \b, size = %sx
+>>3 regex =\ [0-9]+ \b%s
+!:strength + 45
!:mime image/x-portable-bitmap
-0 search/1b P2 Netpbm PGM image text
+0 search/1 P2
+>3 regex =[0-9]*\ [0-9]* Netpbm PGM image text
+>3 regex =[0-9]+\ \b, size = %sx
+>>3 regex =\ [0-9]+ \b%s
+!:strength + 45
!:mime image/x-portable-greymap
0 search/1 P3 Netpbm PPM image text
+>3 regex =[0-9]*\ [0-9]* Netpbm PPM image text
+>3 regex =[0-9]+\ \b, size = %sx
+>>3 regex =\ [0-9]+ \b%s
+!:strength + 45
!:mime image/x-portable-pixmap
-0 string P4 Netpbm PBM "rawbits" image data
+0 string P4
+>3 regex =[0-9]*\ [0-9]* Netpbm PBM "rawbits" image data
+>3 regex =[0-9]+\ \b, size = %sx
+>>3 regex =\ [0-9]+ \b%s
+!:strength + 45
!:mime image/x-portable-bitmap
-0 string P5 Netpbm PGM "rawbits" image data
+0 string P5
+>3 regex =[0-9]*\ [0-9]* Netpbm PGM "rawbits" image data
+>3 regex =[0-9]+\ \b, size = %sx
+>>3 regex =\ [0-9]+ \b%s
+!:strength + 45
!:mime image/x-portable-greymap
-0 string P6 Netpbm PPM "rawbits" image data
+0 string P6
+>3 regex =[0-9]*\ [0-9]* Netpbm PPM "rawbits" image data
+>3 regex =[0-9]+\ \b, size = %sx
+>>3 regex =\ [0-9]+ \b%s
+!:strength + 45
!:mime image/x-portable-pixmap
0 string P7 Netpbm PAM image file
!:mime image/x-portable-pixmap

60
SOURCES/file-localmagic.patch

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
From f25107f625e88726e8ae9d4963573b5a0dda8f4c Mon Sep 17 00:00:00 2001
From: Jan Kaluza <hanzz.k@gmail.com>
Date: Thu, 15 Dec 2011 16:15:41 +0100
Subject: [PATCH] localmagic

---
src/Makefile.am | 2 +-
src/Makefile.in | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index cba64ac..5e48dff 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-MAGIC = $(pkgdatadir)/magic
+MAGIC = /etc/magic:$(pkgdatadir)/magic
lib_LTLIBRARIES = libmagic.la
include_HEADERS = magic.h
diff --git a/magic/magic.local b/magic/magic.local
new file mode 100644
index 0000000..283a863
--- /dev/null
+++ b/magic/magic.local
@@ -0,0 +1,3 @@
+# Magic local data for file(1) command.
+# Insert here your local magic data. Format is described in magic(5).
+
diff --git a/src/Makefile.in b/src/Makefile.in
index 39b1703..3dd92d8 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -240,7 +240,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-MAGIC = $(pkgdatadir)/magic
+MAGIC = /etc/magic:$(pkgdatadir)/magic
lib_LTLIBRARIES = libmagic.la
include_HEADERS = magic.h
AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
diff --git a/src/apprentice.c b/src/apprentice.c
index b330669..0490642 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -281,7 +281,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
#ifndef COMPILE_ONLY
if ((rv = apprentice_map(ms, &magic, &nmagic, fn)) == -1) {
- if (ms->flags & MAGIC_CHECK)
+ if (ms->flags & MAGIC_CHECK && strcmp("/etc/magic", fn) != 0)
file_magwarn(ms, "using regular magic file `%s'", fn);
rv = apprentice_load(ms, &magic, &nmagic, fn, action);
if (rv != 0)

--
1.7.7.4

13
SOURCES/file-python-func.patch

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
diff --git a/magic/Magdir/python b/magic/Magdir/python
index e592803..c786469 100644
--- a/magic/Magdir/python
+++ b/magic/Magdir/python
@@ -59,3 +59,8 @@
!:mime text/x-python
>&0 search/4096 finally: Python script text executable
!:mime text/x-python
+
+# def name(args, args):
+0 regex \^(\ |\\t)*def\ +[a-zA-Z]+
+>&0 regex \ *\\(([a-zA-Z]|,|\ )*\\):$ Python script text executable
+!:mime text/x-python

22
SOURCES/file-qed-vdi-image.patch

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
diff --git a/magic/Magdir/msdos b/magic/Magdir/msdos
index 560d360..83724c5 100644
--- a/magic/Magdir/msdos
+++ b/magic/Magdir/msdos
@@ -815,6 +815,17 @@
0 string/b QEVM QEMU suspend to disk image
+# QEMU QED Image
+# http://wiki.qemu.org/Features/QED/Specification
+0 string/b QED\0 QEMU QED Image
+
+# VDI Image
+64 string/b \x7f\x10\xda\xbe VDI Image
+>68 string/b \x01\x00\x01\x00 version 1.1
+>0 string >\0 (%s)
+>368 lequad x \b, %lld bytes
+
+
0 string/b Bochs\ Virtual\ HD\ Image Bochs disk image,
>32 string x type %s,
>48 string x subtype %s

12
SOURCES/file-tnef.patch

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
diff --git a/magic/Magdir/mail.news b/magic/Magdir/mail.news
index 96fa069..fb5e293 100644
--- a/magic/Magdir/mail.news
+++ b/magic/Magdir/mail.news
@@ -34,6 +34,7 @@
# TNEF files...
0 lelong 0x223E9F78 Transport Neutral Encapsulation Format
+!:mime application/vnd.ms-tnef
# From: Kevin Sullivan <ksulliva@psc.edu>
0 string *mbx* MBX mail folder

1022
SPECS/file.spec

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save