GCC Code Coverage Report


Directory: ../replacer/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 63.3% 38 / 0 / 60
Functions: 85.7% 6 / 0 / 7
Branches: 37.5% 12 / 0 / 32

blamer.c
Line Branch Exec Source
1 /*
2 * blamer.c
3 *
4 * Created on: Oct 15, 2018
5 * Author: alexey
6 */
7
8 #define _POSIX_C_SOURCE 200809L
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <stdint.h>
13 #include <pthread.h>
14 #include <pwd.h>
15 #include <sys/time.h>
16 #include <sys/stat.h>
17 #include <ctype.h>
18
19 #include "unit_test_common.h"
20
21 #include "global_data.h"
22 #include "blamer.h"
23 #include "map/map.h"
24 #include "queue.h"
25
26 #define BLAMER_FILE_ENABLER "/usr/share/i360-php-opts/blamer.enabled"
27 #define DELAY_INTERVAL 500000 // microseconds=0.5s
28
29 /* static __thread int64_t last_send_time = 0; */ /* I didn't delete it before there is commented block of code where
30 last_send_time is using */
31 static int blamer_enabled = 0;
32
33 4 void i360_set_blamer_value(int value) {
34 4 blamer_enabled = value;
35 4 }
36
37 4 int i360_get_blamer_status() {
38 4 return blamer_enabled;
39 }
40
41 #define I360_PARAM_BUF_LEN 15
42 // Yaml зависимая функция, так что осторожнее
43
44 2 void i360_prepare_open_write_recognizer(chain_result *result) {
45 2 result->recognizer_id = I360_RECOGNIZER_ID_INTERNAL;
46 2 result->chain_id = 0;
47 2 result->action = LOG_ONLY;
48 2 result->danger_type = DANGER;
49 2 result->recognizer_desr = I360_RECOGNIZER_ID_INTERNAL_DESC;
50 2 result->ruldescr = "Report open_write or exec function";
51 2 }
52
53 4 void i360_prepare_ef0_hash_recognizer(chain_result *result, int flag, int log_only) {
54 4 int is_black = (HASH_FLAG_BIT(flag) == HASH_FLAG_BIT_BL);
55
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 2 times.
4 result->recognizer_id = log_only ? I360_RECOGNIZER_ID_INTERNAL : I360_RECOGNIZER_ID_COMMON;
56 4 result->action = log_only ? LOG_ONLY : BLOCK_FUNC;
57
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 7 taken 2 times.
4 result->chain_id = is_black ? (HDB_BLOCK_RULE_ID) : (HDB_RULES_BASE + HASH_FLAG_BIT(flag));
58 4 result->danger_type = DANGER;
59
2/2
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 10 taken 2 times.
4 result->recognizer_desr = log_only ? I360_RECOGNIZER_ID_INTERNAL_DESC : I360_RECOGNIZER_ID_COMMON_DESC;
60
2/2
✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 13 taken 2 times.
4 result->ruldescr = is_black ? "Report black hash triggering" : "Report grey hash triggering";
61 4 }
62
63 1 void i360_prepare_ef0_url_hash_recognizer(chain_result *result) {
64 1 result->chain_id = HDB_EF0_URLS_RULE_ID;
65 1 result->action = LOG_ONLY;
66 1 result->ruldescr = "Report black URL hash triggering";
67 1 result->recognizer_id = I360_RECOGNIZER_ID_INTERNAL;
68 1 result->recognizer_desr = I360_RECOGNIZER_ID_INTERNAL_DESC;
69 1 result->danger_type = DANGER;
70 1 }
71
72 2 void i360_prepare_ef1_hash_recognizer(chain_result *result, int log_only) {
73
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
2 result->recognizer_id = log_only ? I360_RECOGNIZER_ID_INTERNAL : I360_RECOGNIZER_ID_COMMON;
74 2 result->action = log_only ? LOG_ONLY : BLOCK_FUNC;
75 2 result->chain_id = HDB_EF1_RULE_ID;
76 2 result->danger_type = DANGER;
77
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 1 time.
2 result->recognizer_desr = log_only ? I360_RECOGNIZER_ID_INTERNAL_DESC : I360_RECOGNIZER_ID_COMMON_DESC;
78 2 result->ruldescr = "Report ef1 hash triggering";
79 2 }
80
81 #define MAX_QUEUE_HASH_ELEMS_LEN 20
82 int _i360_translate_queue_for_hash(const char *queue, char *buffer, int buffer_len) {
83 int len = 0;
84 int counter = 0;
85 int queue_index = 0;
86 char prev = 'a';
87 while (counter < MAX_QUEUE_HASH_ELEMS_LEN && queue[queue_index] && len < buffer_len) {
88 if ((queue[queue_index] >= 'b' && queue[queue_index] <= 'z') ||
89 (queue[queue_index] >= 'B' && queue[queue_index] <= 'Z')) {
90 buffer[len] = queue[queue_index];
91 prev = buffer[len];
92 len++;
93 }
94 if (queue[queue_index] == '|') {
95 if (prev != 'a') {
96 counter++;
97 buffer[len] = '|';
98 len++;
99 }
100 }
101 if (queue[queue_index] == 'a') {
102 prev = queue[queue_index];
103 counter++;
104 }
105 queue_index++;
106 }
107 buffer[len] = 0;
108 return len;
109 }
110