Skip to content

Commit

Permalink
Squidguard.c: using strlen instead of strstr and fflush flushes all b…
Browse files Browse the repository at this point in the history
…uffers now.
  • Loading branch information
Jeroen committed Dec 7, 2011
1 parent b1ad647 commit c8b52af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int blacklist_backend(char *blacklist, char url[URL_SIZE], int debug) {
return 0;
}

while (fgets(line, sizeof(line)-1, fd) != NULL) {
while (fgets(line, URL_SIZE, fd) != NULL) {
char blacklist_url[URL_SIZE];

linenum++;
Expand Down
10 changes: 6 additions & 4 deletions squidguard.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ int squidguard_closefd(FILE *sg_fd[2]) {

int squidguard_backend(FILE *sg_fd[2], char srcip[15], char url[URL_SIZE], int debug) {
char redirect_url[URL_SIZE];
//bzero(redirect_url, sizeof(redirect_url));

fprintf(sg_fd[1], "%s %s/ - - GET\n", url, srcip);
fflush(sg_fd[1]);
while (fgets(redirect_url, sizeof(redirect_url)-1, sg_fd[0]) != NULL) {
fflush(NULL);
while (fgets(redirect_url, URL_SIZE, sg_fd[0]) != NULL) {
redirect_url[strlen(redirect_url) - 1] = '\0';
if (debug > 1)
syslog(LOG_INFO, "squidguard: redirect_url (%s).", redirect_url);
if ((strstr(redirect_url, "http")) != NULL) {
if (strlen(redirect_url) > 1) {
if (debug > 0)
syslog(LOG_INFO, "squidguard: url blocked.");
return 1;
}
if (debug > 0)
syslog(LOG_INFO, "squidguard: url accepted.");
return 0;
}
return 0;
Expand Down

0 comments on commit c8b52af

Please sign in to comment.