CVE-2014-8117.4.90018fe.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Subject: Bump recursion to 15, and allow it to be set from the command line
  2. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  3. Date: Thu Nov 27 15:40:36 2014 +0000
  4. Origin: FILE5_20-34-g90018fe
  5. Last-Update: 2015-01-09
  6. --- a/src/file.c
  7. +++ b/src/file.c
  8. @@ -106,7 +106,7 @@
  9. #undef OPT_LONGONLY
  10. {0, 0, NULL, 0}
  11. };
  12. -#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0"
  13. +#define OPTSTRING "bcCde:f:F:hikLm:nNprR:svz0"
  14. private const struct {
  15. const char *name;
  16. @@ -144,6 +144,7 @@
  17. size_t i;
  18. int action = 0, didsomefiles = 0, errflg = 0;
  19. int flags = 0, e = 0;
  20. + size_t max_recursion = 0;
  21. struct magic_set *magic = NULL;
  22. int longindex;
  23. const char *magicfile = NULL; /* where the magic is */
  24. @@ -244,6 +245,9 @@
  25. case 'r':
  26. flags |= MAGIC_RAW;
  27. break;
  28. + case 'R':
  29. + max_recursion = atoi(optarg);
  30. + break;
  31. case 's':
  32. flags |= MAGIC_DEVICES;
  33. break;
  34. @@ -303,6 +307,15 @@
  35. if (magic == NULL)
  36. if ((magic = load(magicfile, flags)) == NULL)
  37. return 1;
  38. + if (max_recursion) {
  39. + if (magic_setparam(magic, MAGIC_PARAM_MAX_RECURSION,
  40. + &max_recursion) == -1) {
  41. + (void)fprintf(stderr,
  42. + "%s: Can't set recurision %s\n", progname,
  43. + strerror(errno));
  44. + return 1;
  45. + }
  46. + }
  47. break;
  48. }
  49. --- a/src/file.h
  50. +++ b/src/file.h
  51. @@ -363,6 +363,8 @@
  52. /* FIXME: Make the string dynamically allocated so that e.g.
  53. strings matched in files can be longer than MAXstring */
  54. union VALUETYPE ms_value; /* either number or string */
  55. + size_t max_recursion;
  56. +#define FILE_MAX_RECURSION 15
  57. };
  58. /* Type for Unicode characters */
  59. --- a/src/file_opts.h
  60. +++ b/src/file_opts.h
  61. @@ -43,6 +43,7 @@
  62. OPT('p', "preserve-date", 0, " preserve access times on files\n")
  63. #endif
  64. OPT('r', "raw", 0, " don't translate unprintable chars to \\ooo\n")
  65. +OPT('R', "recursion", 0, " set maximum recursion level\n")
  66. OPT('s', "special-files", 0, " treat special (block/char devices) files as\n"
  67. " ordinary ones\n")
  68. OPT('C', "compile", 0, " compile file specified by -m\n")
  69. --- a/src/magic.c
  70. +++ b/src/magic.c
  71. @@ -142,6 +142,7 @@
  72. ms->mlist = NULL;
  73. ms->file = "unknown";
  74. ms->line = 0;
  75. + ms->max_recursion = FILE_MAX_RECURSION;
  76. return ms;
  77. free:
  78. free(ms);
  79. @@ -410,3 +411,29 @@
  80. ms->flags = flags;
  81. return 0;
  82. }
  83. +
  84. +public int
  85. +magic_setparam(struct magic_set *ms, int param, const void *val)
  86. +{
  87. + switch (param) {
  88. + case MAGIC_PARAM_MAX_RECURSION:
  89. + ms->max_recursion = *(const size_t *)val;
  90. + return 0;
  91. + default:
  92. + errno = EINVAL;
  93. + return -1;
  94. + }
  95. +}
  96. +
  97. +public int
  98. +magic_getparam(struct magic_set *ms, int param, void *val)
  99. +{
  100. + switch (param) {
  101. + case MAGIC_PARAM_MAX_RECURSION:
  102. + *(size_t *)val = ms->max_recursion;
  103. + return 0;
  104. + default:
  105. + errno = EINVAL;
  106. + return -1;
  107. + }
  108. +}
  109. --- a/src/magic.h
  110. +++ b/src/magic.h
  111. @@ -82,6 +82,10 @@
  112. int magic_check(magic_t, const char *);
  113. int magic_errno(magic_t);
  114. +#define MAGIC_PARAM_MAX_RECURSION 0
  115. +int magic_setparam(magic_t, int, const void *);
  116. +int magic_getparam(magic_t, int, void *);
  117. +
  118. #ifdef __cplusplus
  119. };
  120. #endif
  121. --- a/src/softmagic.c
  122. +++ b/src/softmagic.c
  123. @@ -43,9 +43,9 @@
  124. private int match(struct magic_set *, struct magic *, uint32_t,
  125. - const unsigned char *, size_t, int, int);
  126. + const unsigned char *, size_t, int, size_t);
  127. private int mget(struct magic_set *, const unsigned char *,
  128. - struct magic *, size_t, unsigned int, int);
  129. + struct magic *, size_t, unsigned int, size_t);
  130. private int magiccheck(struct magic_set *, struct magic *);
  131. private int32_t mprint(struct magic_set *, struct magic *);
  132. private int32_t moffset(struct magic_set *, struct magic *);
  133. @@ -62,8 +62,6 @@
  134. #define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
  135. -#define MAX_RECURSION_LEVEL 10
  136. -
  137. /*
  138. * softmagic - lookup one file in parsed, in-memory copy of database
  139. * Passed the name and FILE * of one file to be typed.
  140. @@ -110,7 +108,7 @@
  141. */
  142. private int
  143. match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
  144. - const unsigned char *s, size_t nbytes, int mode, int recursion_level)
  145. + const unsigned char *s, size_t nbytes, int mode, size_t recursion_level)
  146. {
  147. uint32_t magindex = 0;
  148. unsigned int cont_level = 0;
  149. @@ -1049,7 +1047,7 @@
  150. private int
  151. mget(struct magic_set *ms, const unsigned char *s,
  152. - struct magic *m, size_t nbytes, unsigned int cont_level, int recursion_level)
  153. + struct magic *m, size_t nbytes, unsigned int cont_level, size_t recursion_level)
  154. {
  155. uint32_t offset = ms->offset;
  156. file_pushbuf_t *pb;
  157. @@ -1057,7 +1055,7 @@
  158. char *rbuf;
  159. union VALUETYPE *p = &ms->ms_value;
  160. - if (recursion_level >= MAX_RECURSION_LEVEL) {
  161. + if (recursion_level >= ms->max_recursion) {
  162. file_error(ms, 0, "recursion nesting exceeded");
  163. return -1;
  164. }