cherry-pick.FILE5_35-8-g42d9a8a3.need-to-pass-found-match-from-match-mget-match-so-that-the-use-case.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Subject: Need to pass found_match from match -> mget -> match so that the USE case (...)
  2. Origin: FILE5_35-8-g42d9a8a3 <https://github.com/file/file/commit/FILE5_35-8-g42d9a8a3>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Mon Nov 5 18:03:25 2018 +0000
  5. Need to pass found_match from match -> mget -> match so that the USE case
  6. propagates the value.
  7. --- a/src/softmagic.c
  8. +++ b/src/softmagic.c
  9. @@ -45,11 +45,11 @@
  10. private int match(struct magic_set *, struct magic *, uint32_t,
  11. const struct buffer *, size_t, int, int, int, uint16_t *,
  12. - uint16_t *, int *, int *, int *);
  13. + uint16_t *, int *, int *, int *, int *);
  14. private int mget(struct magic_set *, struct magic *, const struct buffer *,
  15. const unsigned char *, size_t,
  16. size_t, unsigned int, int, int, int, uint16_t *,
  17. - uint16_t *, int *, int *, int *);
  18. + uint16_t *, int *, int *, int *, int *);
  19. private int msetoffset(struct magic_set *, struct magic *, struct buffer *,
  20. const struct buffer *, size_t, unsigned int);
  21. private int magiccheck(struct magic_set *, struct magic *);
  22. @@ -111,7 +111,7 @@
  23. for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
  24. if ((rv = match(ms, ml->magic, ml->nmagic, b, 0, mode,
  25. text, 0, indir_count, name_count,
  26. - &printed_something, &need_separator, NULL)) != 0)
  27. + &printed_something, &need_separator, NULL, NULL)) != 0)
  28. return rv;
  29. return 0;
  30. @@ -167,11 +167,12 @@
  31. match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
  32. const struct buffer *b, size_t offset, int mode, int text,
  33. int flip, uint16_t *indir_count, uint16_t *name_count,
  34. - int *printed_something, int *need_separator, int *returnval)
  35. + int *printed_something, int *need_separator, int *returnval,
  36. + int *found_match)
  37. {
  38. uint32_t magindex = 0;
  39. unsigned int cont_level = 0;
  40. - int found_match = 0; /* if a match is found it is set to 1*/
  41. + int found_matchv = 0; /* if a match is found it is set to 1*/
  42. int returnvalv = 0, e;
  43. int firstline = 1; /* a flag to print X\n X\n- X */
  44. struct buffer bb;
  45. @@ -183,6 +184,8 @@
  46. */
  47. if (returnval == NULL)
  48. returnval = &returnvalv;
  49. + if (found_match == NULL)
  50. + found_match = &found_matchv;
  51. if (file_check_mem(ms, cont_level) == -1)
  52. return -1;
  53. @@ -214,7 +217,8 @@
  54. switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf),
  55. bb.flen, offset, cont_level,
  56. mode, text, flip, indir_count, name_count,
  57. - printed_something, need_separator, returnval)) {
  58. + printed_something, need_separator, returnval, found_match))
  59. + {
  60. case -1:
  61. return -1;
  62. case 0:
  63. @@ -222,7 +226,7 @@
  64. break;
  65. default:
  66. if (m->type == FILE_INDIRECT) {
  67. - found_match = 1;
  68. + *found_match = 1;
  69. *returnval = 1;
  70. }
  71. @@ -247,7 +251,7 @@
  72. }
  73. if (*m->desc)
  74. - found_match = 1;
  75. + *found_match = 1;
  76. if ((e = handle_annotation(ms, m, firstline)) != 0)
  77. {
  78. @@ -315,7 +319,7 @@
  79. bb.fbuf), bb.flen, offset,
  80. cont_level, mode, text, flip, indir_count,
  81. name_count, printed_something, need_separator,
  82. - returnval)) {
  83. + returnval, found_match)) {
  84. case -1:
  85. return -1;
  86. case 0:
  87. @@ -325,7 +329,7 @@
  88. break;
  89. default:
  90. if (m->type == FILE_INDIRECT) {
  91. - found_match = 1;
  92. + *found_match = 1;
  93. *returnval = 1;
  94. }
  95. flush = 0;
  96. @@ -353,7 +357,7 @@
  97. ms->c.li[cont_level].got_match = 1;
  98. if (*m->desc)
  99. - found_match = 1;
  100. + *found_match = 1;
  101. if ((e = handle_annotation(ms, m, firstline))
  102. != 0) {
  103. @@ -1476,7 +1480,8 @@
  104. mget(struct magic_set *ms, struct magic *m, const struct buffer *b,
  105. const unsigned char *s, size_t nbytes, size_t o, unsigned int cont_level,
  106. int mode, int text, int flip, uint16_t *indir_count, uint16_t *name_count,
  107. - int *printed_something, int *need_separator, int *returnval)
  108. + int *printed_something, int *need_separator, int *returnval,
  109. + int *found_match)
  110. {
  111. uint32_t offset = ms->offset;
  112. struct buffer bb;
  113. @@ -1762,7 +1767,7 @@
  114. *need_separator = 0;
  115. rv = match(ms, ml.magic, ml.nmagic, b, offset + o,
  116. mode, text, flip, indir_count, name_count,
  117. - printed_something, need_separator, returnval);
  118. + printed_something, need_separator, returnval, found_match);
  119. (*name_count)--;
  120. if (rv != 1)
  121. *need_separator = oneed_separator;