TEMP-0000000-B67840.8.af444af.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. Subject: Remove name recursion limit, it is always lower than the count... Rename things for consistency
  2. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  3. Date: Fri Nov 28 02:46:39 2014 +0000
  4. Origin: FILE5_20-38-gaf444af
  5. Last-Update: 2015-01-05
  6. Remove name recursion limit, it is always lower than the count... Rename
  7. things for consistency.
  8. (prequisite for TEMP-0000000-B67840)
  9. diff --git a/doc/file.man b/doc/file.man
  10. index 8ea29ef..dd80d08 100644
  11. --- a/doc/file.man
  12. +++ b/doc/file.man
  13. @@ -293,13 +293,12 @@ attempt to preserve the access time of files analyzed, to pretend that
  14. never read them.
  15. .It Fl P , Fl Fl parameter Ar name=value
  16. Set various parameter limits.
  17. -.Bl -column "namenum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
  18. +.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
  19. .It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
  20. .It Li indir Ta 15 Ta recursion limit for indirect magic
  21. -.It Li name Ta 40 Ta recursion limit for name/use magic
  22. -.It Li namenum Ta 30 Ta use count limit for name/use magic
  23. -.It Li phnum Ta 128 Ta max ELF program sections processed
  24. -.It Li shnum Ta 32768 Ta max ELF sections processed
  25. +.It Li name Ta 30 Ta use count limit for name/use magic
  26. +.It Li elf_phnum Ta 128 Ta max ELF program sections processed
  27. +.It Li elf_shnum Ta 32768 Ta max ELF sections processed
  28. .El
  29. .It Fl r , Fl Fl raw
  30. Don't translate unprintable characters to \eooo.
  31. diff --git a/doc/libmagic.man b/doc/libmagic.man
  32. index 57ec7dc..d45e3c8 100644
  33. --- a/doc/libmagic.man
  34. +++ b/doc/libmagic.man
  35. @@ -258,13 +258,12 @@ and
  36. .Fn magic_setparam
  37. allow getting and setting various limits related to the the magic
  38. library.
  39. -.Bl -column "MAGIC_PARAM_INDIR_RECURSION" "size_t" "Default" -offset indent
  40. +.Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent
  41. .It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"
  42. -.It Li MAGIC_PARAM_INDIR_RECURSION Ta size_t Ta 15
  43. -.It Li MAGIC_PARAM_NAME_RECURSION Ta size_t Ta 40
  44. +.It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15
  45. .It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30
  46. -.It Li MAGIC_PARAM_PHNUM_MAX Ta size_t Ta 128
  47. -.It Li MAGIC_PARAM_SHNUM_MAX Ta size_t Ta 32768
  48. +.It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128
  49. +.It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768
  50. .El
  51. .Pp
  52. The
  53. diff --git a/src/ascmagic.c b/src/ascmagic.c
  54. index 3388682..463c614 100644
  55. --- a/src/ascmagic.c
  56. +++ b/src/ascmagic.c
  57. @@ -147,7 +147,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
  58. == NULL)
  59. goto done;
  60. if ((rv = file_softmagic(ms, utf8_buf,
  61. - (size_t)(utf8_end - utf8_buf), 0, 0, NULL,
  62. + (size_t)(utf8_end - utf8_buf), 0, NULL,
  63. TEXTTEST, text)) == 0)
  64. rv = -1;
  65. }
  66. diff --git a/src/elfclass.h b/src/elfclass.h
  67. index bda53b3..e144d11 100644
  68. --- a/src/elfclass.h
  69. +++ b/src/elfclass.h
  70. @@ -36,7 +36,7 @@
  71. #ifdef ELFCORE
  72. case ET_CORE:
  73. phnum = elf_getu16(swap, elfhdr.e_phnum);
  74. - if (phnum > ms->phnum_max)
  75. + if (phnum > ms->elf_phnum_max)
  76. return toomany(ms, "program", phnum);
  77. flags |= FLAGS_IS_CORE;
  78. if (dophn_core(ms, clazz, swap, fd,
  79. @@ -49,10 +49,10 @@
  80. case ET_EXEC:
  81. case ET_DYN:
  82. phnum = elf_getu16(swap, elfhdr.e_phnum);
  83. - if (phnum > ms->phnum_max)
  84. + if (phnum > ms->elf_phnum_max)
  85. return toomany(ms, "program", phnum);
  86. shnum = elf_getu16(swap, elfhdr.e_shnum);
  87. - if (shnum > ms->shnum_max)
  88. + if (shnum > ms->elf_shnum_max)
  89. return toomany(ms, "section", shnum);
  90. if (dophn_exec(ms, clazz, swap, fd,
  91. (off_t)elf_getu(swap, elfhdr.e_phoff), phnum,
  92. @@ -62,7 +62,7 @@
  93. /*FALLTHROUGH*/
  94. case ET_REL:
  95. shnum = elf_getu16(swap, elfhdr.e_shnum);
  96. - if (shnum > ms->shnum_max)
  97. + if (shnum > ms->elf_shnum_max)
  98. return toomany(ms, "section", shnum);
  99. if (doshn(ms, clazz, swap, fd,
  100. (off_t)elf_getu(swap, elfhdr.e_shoff), shnum,
  101. diff --git a/src/file.c b/src/file.c
  102. index 702a613..5ce08aa 100644
  103. --- a/src/file.c
  104. +++ b/src/file.c
  105. @@ -124,11 +124,10 @@ private struct {
  106. int tag;
  107. size_t value;
  108. } pm[] = {
  109. - { "indir", MAGIC_PARAM_INDIR_RECURSION, 0 },
  110. - { "name", MAGIC_PARAM_NAME_RECURSION, 0 },
  111. - { "namenum", MAGIC_PARAM_NAME_MAX, 0 },
  112. - { "phnum", MAGIC_PARAM_PHNUM_MAX, 0 },
  113. - { "shnum", MAGIC_PARAM_SHNUM_MAX, 0 },
  114. + { "indir", MAGIC_PARAM_INDIR_MAX, 0 },
  115. + { "name", MAGIC_PARAM_NAME_MAX, 0 },
  116. + { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
  117. + { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
  118. };
  119. private char *progname; /* used throughout */
  120. diff --git a/src/file.h b/src/file.h
  121. index 6692b3a..67331e0 100644
  122. --- a/src/file.h
  123. +++ b/src/file.h
  124. @@ -380,16 +380,14 @@ struct magic_set {
  125. /* FIXME: Make the string dynamically allocated so that e.g.
  126. strings matched in files can be longer than MAXstring */
  127. union VALUETYPE ms_value; /* either number or string */
  128. - uint16_t indir_recursion;
  129. - uint16_t name_recursion;
  130. + uint16_t indir_max;
  131. uint16_t name_max;
  132. - uint16_t shnum_max;
  133. - uint16_t phnum_max;
  134. -#define FILE_INDIR_RECURSION 15
  135. -#define FILE_NAME_RECURSION 40
  136. -#define FILE_NAME_MAX 30
  137. -#define FILE_ELF_SHNUM 32768
  138. -#define FILE_ELF_PHNUM 128
  139. + uint16_t elf_shnum_max;
  140. + uint16_t elf_phnum_max;
  141. +#define FILE_INDIR_MAX 15
  142. +#define FILE_NAME_MAX 30
  143. +#define FILE_ELF_SHNUM_MAX 32768
  144. +#define FILE_ELF_PHNUM_MAX 128
  145. };
  146. /* Type for Unicode characters */
  147. @@ -424,7 +422,7 @@ protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
  148. unichar **, size_t *, const char **, const char **, const char **);
  149. protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
  150. protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
  151. - uint16_t, uint16_t, uint16_t *, int, int);
  152. + uint16_t, uint16_t *, int, int);
  153. protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
  154. protected uint64_t file_signextend(struct magic_set *, struct magic *,
  155. uint64_t);
  156. diff --git a/src/funcs.c b/src/funcs.c
  157. index 91b11fc..e7d2bb8 100644
  158. --- a/src/funcs.c
  159. +++ b/src/funcs.c
  160. @@ -228,7 +228,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
  161. /* try soft magic tests */
  162. if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
  163. - if ((m = file_softmagic(ms, ubuf, nb, 0, 0, NULL, BINTEST,
  164. + if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,
  165. looks_text)) != 0) {
  166. if ((ms->flags & MAGIC_DEBUG) != 0)
  167. (void)fprintf(stderr, "softmagic %d\n", m);
  168. diff --git a/src/magic.c b/src/magic.c
  169. index f2bdae5..3aa3474 100644
  170. --- a/src/magic.c
  171. +++ b/src/magic.c
  172. @@ -233,11 +233,10 @@ magic_open(int flags)
  173. ms->mlist = NULL;
  174. ms->file = "unknown";
  175. ms->line = 0;
  176. - ms->indir_recursion = FILE_INDIR_RECURSION;
  177. - ms->name_recursion = FILE_NAME_RECURSION;
  178. + ms->indir_max = FILE_INDIR_MAX;
  179. ms->name_max = FILE_NAME_MAX;
  180. - ms->shnum_max = FILE_ELF_SHNUM;
  181. - ms->phnum_max = FILE_ELF_PHNUM;
  182. + ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;
  183. + ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;
  184. return ms;
  185. free:
  186. free(ms);
  187. @@ -521,20 +520,17 @@ public int
  188. magic_setparam(struct magic_set *ms, int param, const void *val)
  189. {
  190. switch (param) {
  191. - case MAGIC_PARAM_INDIR_RECURSION:
  192. - ms->indir_recursion = *(const size_t *)val;
  193. - return 0;
  194. - case MAGIC_PARAM_NAME_RECURSION:
  195. - ms->name_recursion = *(const size_t *)val;
  196. + case MAGIC_PARAM_INDIR_MAX:
  197. + ms->indir_max = *(const size_t *)val;
  198. return 0;
  199. case MAGIC_PARAM_NAME_MAX:
  200. ms->name_max = *(const size_t *)val;
  201. return 0;
  202. - case MAGIC_PARAM_PHNUM_MAX:
  203. - ms->phnum_max = *(const size_t *)val;
  204. + case MAGIC_PARAM_ELF_PHNUM_MAX:
  205. + ms->elf_phnum_max = *(const size_t *)val;
  206. return 0;
  207. - case MAGIC_PARAM_SHNUM_MAX:
  208. - ms->shnum_max = *(const size_t *)val;
  209. + case MAGIC_PARAM_ELF_SHNUM_MAX:
  210. + ms->elf_shnum_max = *(const size_t *)val;
  211. return 0;
  212. default:
  213. errno = EINVAL;
  214. @@ -546,20 +542,17 @@ public int
  215. magic_getparam(struct magic_set *ms, int param, void *val)
  216. {
  217. switch (param) {
  218. - case MAGIC_PARAM_INDIR_RECURSION:
  219. - *(size_t *)val = ms->indir_recursion;
  220. - return 0;
  221. - case MAGIC_PARAM_NAME_RECURSION:
  222. - *(size_t *)val = ms->name_recursion;
  223. + case MAGIC_PARAM_INDIR_MAX:
  224. + *(size_t *)val = ms->indir_max;
  225. return 0;
  226. case MAGIC_PARAM_NAME_MAX:
  227. *(size_t *)val = ms->name_max;
  228. return 0;
  229. - case MAGIC_PARAM_PHNUM_MAX:
  230. - *(size_t *)val = ms->phnum_max;
  231. + case MAGIC_PARAM_ELF_PHNUM_MAX:
  232. + *(size_t *)val = ms->elf_phnum_max;
  233. return 0;
  234. - case MAGIC_PARAM_SHNUM_MAX:
  235. - *(size_t *)val = ms->shnum_max;
  236. + case MAGIC_PARAM_ELF_SHNUM_MAX:
  237. + *(size_t *)val = ms->elf_shnum_max;
  238. return 0;
  239. default:
  240. errno = EINVAL;
  241. diff --git a/src/softmagic.c b/src/softmagic.c
  242. index 6e94ae9..9a13acb 100644
  243. --- a/src/softmagic.c
  244. +++ b/src/softmagic.c
  245. @@ -43,9 +43,9 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.147 2011/11/05 15:44:22 rrt Exp $")
  246. private int match(struct magic_set *, struct magic *, uint32_t,
  247. - const unsigned char *, size_t, int, int, uint16_t, uint16_t, uint16_t *);
  248. + const unsigned char *, size_t, int, int, uint16_t, uint16_t *);
  249. private int mget(struct magic_set *, const unsigned char *,
  250. - struct magic *, size_t, unsigned int, int, uint16_t, uint16_t, uint16_t *);
  251. + struct magic *, size_t, unsigned int, int, uint16_t, uint16_t *);
  252. private int magiccheck(struct magic_set *, struct magic *);
  253. private int32_t mprint(struct magic_set *, struct magic *);
  254. private int32_t moffset(struct magic_set *, struct magic *);
  255. @@ -69,8 +69,7 @@ private void cvt_64(union VALUETYPE *, const struct magic *);
  256. /*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
  257. protected int
  258. file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
  259. - uint16_t indir_level, uint16_t name_level, uint16_t *name_count,
  260. - int mode, int text)
  261. + uint16_t indir_level, uint16_t *name_count, int mode, int text)
  262. {
  263. struct mlist *ml;
  264. uint16_t nc;
  265. @@ -82,7 +81,7 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
  266. int rv;
  267. for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
  268. if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode,
  269. - text, indir_level, name_level, name_count)) != 0)
  270. + text, indir_level, name_count)) != 0)
  271. return rv;
  272. return 0;
  273. @@ -118,7 +117,7 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
  274. private int
  275. match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
  276. const unsigned char *s, size_t nbytes, int mode, int text,
  277. - uint16_t indir_level, uint16_t name_level, uint16_t *name_count)
  278. + uint16_t indir_level, uint16_t *name_count)
  279. {
  280. uint32_t magindex = 0;
  281. unsigned int cont_level = 0;
  282. @@ -150,7 +149,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
  283. ms->line = m->lineno;
  284. /* if main entry matches, print it... */
  285. - switch (mget(ms, s, m, nbytes, cont_level, text, indir_level, name_level, name_count)) {
  286. + switch (mget(ms, s, m, nbytes, cont_level, text, indir_level, name_count)) {
  287. case -1:
  288. return -1;
  289. case 0:
  290. @@ -233,7 +232,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
  291. continue;
  292. }
  293. #endif
  294. - switch (mget(ms, s, m, nbytes, cont_level, text, indir_level, name_level, name_count)) {
  295. + switch (mget(ms, s, m, nbytes, cont_level, text, indir_level, name_count)) {
  296. case -1:
  297. return -1;
  298. case 0:
  299. @@ -1049,7 +1048,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
  300. private int
  301. mget(struct magic_set *ms, const unsigned char *s,
  302. struct magic *m, size_t nbytes, unsigned int cont_level, int text,
  303. - uint16_t indir_level, uint16_t name_level, uint16_t *name_count)
  304. + uint16_t indir_level, uint16_t *name_count)
  305. {
  306. uint32_t offset = ms->offset;
  307. file_pushbuf_t *pb;
  308. @@ -1057,18 +1056,12 @@ mget(struct magic_set *ms, const unsigned char *s,
  309. char *rbuf;
  310. union VALUETYPE *p = &ms->ms_value;
  311. - if (indir_level >= ms->indir_recursion) {
  312. + if (indir_level >= ms->indir_max) {
  313. file_error(ms, 0, "indirect recursion nesting (%hu) exceeded",
  314. indir_level);
  315. return -1;
  316. }
  317. - if (name_level >= ms->name_recursion) {
  318. - file_error(ms, 0, "name recursion nesting (%hu) exceeded",
  319. - name_level);
  320. - return -1;
  321. - }
  322. -
  323. if (*name_count >= ms->name_max) {
  324. file_error(ms, 0, "name use count (%hu) exceeded",
  325. *name_count);
  326. @@ -1638,7 +1631,7 @@ mget(struct magic_set *ms, const unsigned char *s,
  327. return -1;
  328. rv = file_softmagic(ms, s + offset, nbytes - offset,
  329. - indir_level + 1, name_level, name_count, BINTEST, text);
  330. + indir_level + 1, name_count, BINTEST, text);
  331. if ((ms->flags & MAGIC_DEBUG) != 0)
  332. fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);