Guest User

Untitled

a guest
Jan 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. diff --git bsm.c bsm.c
  2. index 97663f8..b592c74 100644
  3. --- bsm.c
  4. +++ bsm.c
  5. @@ -65,11 +65,11 @@ bsm_match_event(struct bsm_state *bm, struct bsm_record_data *bd)
  6. for (i = 0; i < a->a_cnt; i++) {
  7. switch (bm->bm_event_type) {
  8. case SET_TYPE_AUCLASS:
  9. - if ((evdata & a->a_data.value[i]) != 0)
  10. + if ((evdata & a->a_data[i].value) != 0)
  11. match = 1;
  12. break;
  13. case SET_TYPE_AUEVENT:
  14. - if (a->a_data.value[i] == evdata)
  15. + if (a->a_data[i].value == evdata)
  16. match = 1;
  17. }
  18. }
  19. @@ -151,8 +151,8 @@ bsm_match_object(struct bsm_state *bm, struct bsm_record_data *bd)
  20. */
  21. if (ap->a_type == STRING_ARRAY) {
  22. for (match = 0, i = 0; i < ap->a_cnt; i++) {
  23. - slen = strlen(ap->a_data.string[i]);
  24. - if (strncmp(ap->a_data.string[i], bd->br_path, slen)
  25. + slen = strlen(ap->a_data[i].string);
  26. + if (strncmp(ap->a_data[i].string, bd->br_path, slen)
  27. == 0) {
  28. match = 1;
  29. break;
  30. @@ -162,14 +162,14 @@ bsm_match_object(struct bsm_state *bm, struct bsm_record_data *bd)
  31. } else if (ap->a_type == PCRE_ARRAY) {
  32. slen = strlen(bd->br_path);
  33. for (match = 0, i = 0; i < ap->a_cnt; i++) {
  34. - rc = pcre_exec(ap->a_data.pcre[i], NULL, bd->br_path,
  35. + rc = pcre_exec(ap->a_data[i].pcre, NULL, bd->br_path,
  36. slen, 0, 0, NULL, 0);
  37. if (rc == 0) {
  38. match = 1;
  39. break;
  40. } else if (rc < -1) {
  41. bsmtrace_error(0, "pcre exec failed for pattern"
  42. - " %s on path %s", ap->a_data.pcre[i],
  43. + " %s on path %s", ap->a_data[i].pcre,
  44. bd->br_path);
  45. }
  46. }
  47. @@ -237,7 +237,7 @@ bsm_check_subj_array(u_int subj, struct array *ap)
  48. int match, i;
  49.  
  50. for (match = 0, i = 0; i < ap->a_cnt; i++)
  51. - if (ap->a_data.value[i] == subj)
  52. + if (ap->a_data[i].value == subj)
  53. match = 1;
  54. if (ap->a_negated != 0)
  55. match = !match;
  56. diff --git conf.c conf.c
  57. index b68e1a1..0f1d438 100644
  58. --- conf.c
  59. +++ conf.c
  60. @@ -28,6 +28,7 @@
  61. * SUCH DAMAGE.
  62. */
  63. #include "includes.h"
  64. +#include <err.h>
  65.  
  66. static const struct _settype_tab {
  67. char *stt_str;
  68. @@ -136,6 +137,15 @@ conf_array_add(const char *str, struct array *a, int type)
  69. pcre *re;
  70. #endif
  71.  
  72. + if (a->a_cnt >= a->a_size) {
  73. + union array_data *tmp = realloc(a->a_data, (a->a_size + BSM_ARRAY_MAX));
  74. + if (tmp == NULL) {
  75. + err(1, "Failed to allocate memory");
  76. + }
  77. + a->a_size += BSM_ARRAY_MAX;
  78. + a->a_data = tmp;
  79. + }
  80. +
  81. e = 0;
  82. switch (type) {
  83. case SET_TYPE_AUCLASS:
  84. @@ -200,15 +210,15 @@ conf_array_add(const char *str, struct array *a, int type)
  85. conf_detail(0, "%s: invalid %s name\n", str, estring);
  86. }
  87. if (type == SET_TYPE_PATH || type == SET_TYPE_LOGCHANNEL) {
  88. - a->a_data.string[a->a_cnt++] = ptr;
  89. + a->a_data[a->a_cnt++].string = ptr;
  90. a->a_type = STRING_ARRAY;
  91. #ifdef PCRE
  92. } else if (type == SET_TYPE_PCRE) {
  93. - a->a_data.pcre[a->a_cnt++] = re;
  94. + a->a_data[a->a_cnt++].pcre = re;
  95. a->a_type = PCRE_ARRAY;
  96. #endif
  97. } else {
  98. - a->a_data.value[a->a_cnt++] = value;
  99. + a->a_data[a->a_cnt++].value = value;
  100. a->a_type = INTEGER_ARRAY;
  101. }
  102. }
  103. @@ -295,7 +305,7 @@ conf_set_log_channel(struct bsm_set *bss, struct bsm_sequence *bs)
  104.  
  105. a = &bss->bss_data;
  106. for (i = 0; i < a->a_cnt; i++) {
  107. - lc = log_lookup_channel(a->a_data.string[i]);
  108. + lc = log_lookup_channel(a->a_data[i].string);
  109. if (lc == NULL)
  110. conf_detail(0, "unable to lookup channel");
  111. TAILQ_INSERT_HEAD(&bs->bs_log_channel, lc, log_glue);
  112. diff --git deuce.h deuce.h
  113. index 4ae7972..4bf3611 100644
  114. --- deuce.h
  115. +++ deuce.h
  116. @@ -55,6 +55,14 @@ enum {
  117. SET_TYPE_LOGCHANNEL
  118. };
  119.  
  120. +union array_data {
  121. + int value;
  122. + char *string;
  123. +#ifdef PCRE
  124. + pcre *pcre;
  125. +#endif
  126. +};
  127. +
  128. struct array {
  129. int a_type; /* Content type of a_data */
  130. int a_negated;
  131. @@ -63,19 +71,9 @@ struct array {
  132. #ifdef PCRE
  133. #define PCRE_ARRAY 4
  134. #endif
  135. - int a_cnt;
  136. - /*
  137. - * NB: Perhaps in the future, these arrays will auto
  138. - * scale based on the demand. But for now, just make
  139. - * them static.
  140. - */
  141. - union {
  142. - int value[BSM_ARRAY_MAX];
  143. - char *string[BSM_ARRAY_MAX];
  144. -#ifdef PCRE
  145. - pcre *pcre[BSM_ARRAY_MAX];
  146. -#endif
  147. - } a_data;
  148. + size_t a_cnt;
  149. + size_t a_size;
  150. + union array_data *a_data;
  151. };
  152.  
  153. /*
  154. diff --git grammar.y grammar.y
  155. index 947987c..34edbdb 100644
  156. --- grammar.y
  157. +++ grammar.y
  158. @@ -90,6 +90,7 @@ define_def:
  159. src = $9;
  160. dst = &set_state->bss_data;
  161. *dst = *src;
  162. + free(array_state.a_data);
  163. bzero(&array_state, sizeof(struct array));
  164. TAILQ_INSERT_TAIL(&bsm_set_head, set_state, bss_glue);
  165. set_state = NULL;
  166. @@ -181,6 +182,7 @@ anon_set:
  167. src = $6;
  168. dst = &set_state->bss_data;
  169. *dst = *src;
  170. + free(array_state.a_data);
  171. bzero(&array_state, sizeof(struct array));
  172. $$ = set_state;
  173. set_state = NULL;
  174. @@ -390,6 +392,7 @@ type_spec:
  175. src = &ptr->bss_data;
  176. dst = &bm_state->bm_auditevent;
  177. *dst = *src;
  178. + free(array_state.a_data);
  179. bzero(&array_state, sizeof(struct array));
  180. dst->a_negated = $2;
  181. }
  182. @@ -405,6 +408,7 @@ type_spec:
  183. src = &$3->bss_data;
  184. dst = &bm_state->bm_auditevent;
  185. *dst = *src;
  186. + free(array_state.a_data);
  187. bzero(&array_state, sizeof(struct array));
  188. dst->a_negated = $2;
  189. }
  190. @@ -412,6 +416,7 @@ type_spec:
  191. {
  192. bm_state->bm_event_type = SET_TYPE_AUEVENT;
  193. bm_state->bm_event_flags |= BSM_STATE_EVENT_ANY;
  194. + free(array_state.a_data);
  195. bzero(&array_state, sizeof(struct array));
  196. }
  197. ;
  198. @@ -435,6 +440,7 @@ object_spec:
  199. src = &ptr->bss_data;
  200. dst = &bm_state->bm_objects;
  201. *dst = *src;
  202. + free(array_state.a_data);
  203. bzero(&array_state, sizeof(struct array));
  204. dst->a_negated = $2;
  205. }
  206. @@ -453,6 +459,7 @@ object_spec:
  207. #endif
  208. dst = &bm_state->bm_objects;
  209. *dst = *src;
  210. + free(array_state.a_data);
  211. bzero(&array_state, sizeof(struct array));
  212. dst->a_negated = $2;
  213. }
Add Comment
Please, Sign In to add comment