Skip to content

Commit 7e031dd

Browse files
Matej BarnatMatej Barnat
Matej Barnat
authored and
Matej Barnat
committed
url_blacklist_filter - compare full URL when checking if it is blacklisted
1 parent 3da9e9d commit 7e031dd

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

url_blacklist_filter/url_blacklist_filter.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,27 +182,10 @@ void clean_pid_file(char *pid_file){
182182
}
183183

184184

185-
bool ends_with_substring(char *str, char *substr){
186-
// check if str ends with substr
187-
size_t str_len = strlen(str);
188-
size_t substr_len = strlen(substr);
189-
if (str_len < substr_len) {
190-
return false;
191-
}
192-
int i = strncmp(str + str_len - substr_len, substr, substr_len);
193-
if (i == 0) {
194-
return true;
195-
} else {
196-
return false;
197-
}
198-
}
199-
200-
201-
bool is_malicious(char *url, char **malicious_urls){
202-
// check if url is malicious
203-
char *found;
185+
bool is_listed(char *url, char **malicious_urls) {
186+
// Check if URL is listed on the blacklist
204187
for (int i = 0; i < blacklist_size; i++) {
205-
if (ends_with_substring(malicious_urls[i], url)) {
188+
if (strcmp(url, malicious_urls[i]) == 0) {
206189
return true;
207190
}
208191
}
@@ -373,7 +356,7 @@ int main(int argc, char **argv)
373356
full_url[path_len + host_len] = '\0';
374357

375358
// Check if URL is in the list of malicious URLs, if not continue
376-
if (!is_malicious(full_url, malicious_urls)) {
359+
if (!is_listed(full_url, malicious_urls)) {
377360
if (verbose_print) {
378361
printf("URL \"%s\" -> CLEAN\n", full_url);
379362
}

0 commit comments

Comments
 (0)