Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed fix for CVE-2020-8445 #2094

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/analysisd/cleanevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ int OS_CleanMSG(char *msg, Eventinfo *lf)

os_strdup(msg, lf->location);

/*CVE-2020-8445 fix*/
remove_control_characters(pieces);

/* Get the log length */
loglen = strlen(pieces) + 1;

Expand Down Expand Up @@ -467,7 +470,7 @@ int OS_CleanMSG(char *msg, Eventinfo *lf)
(done_message == 0)) {
pieces += 8;
done_message = 1;

lf->log = pieces;

/* Get the closing brackets */
Expand Down
10 changes: 7 additions & 3 deletions src/headers/file_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#define __FILE_H

#include <time.h>

#define OS_PIDFILE "/var/run"
#include <stdbool.h>
#define OS_PIDFILE "/var/run"

/* Set the program name - must be done before *anything* else */
void OS_SetName(const char *name) __attribute__((nonnull));
Expand Down Expand Up @@ -59,5 +59,9 @@ int checkVista();
int isVista;
#endif

int w_ref_parent_folder(const char * path);
int w_ref_parent_folder(const char *path);

void remove_control_characters(char *str);

bool is_control_character(char c);
#endif /* __FILE_H */
22 changes: 21 additions & 1 deletion src/shared/file_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <errno.h>
#include <string.h>

#include <stdbool.h>
#include "shared.h"

#ifndef WIN32
Expand Down Expand Up @@ -1582,3 +1582,23 @@ int w_ref_parent_folder(const char * path) {

return 0;
}

bool is_control_character(char c) {
return (c >= 0 && c <= 31) || c == 127 || c == '\n';
}

void remove_control_characters(char *str) {
int len = strlen(str);
int i, j;

for (i = 0, j = 0; i < len; i++) {
if (!is_control_character(str[i])) {
str[j] = str[i];
j++;
} else {
DEBUG_MSG("%s:DEBUG: control character removed: %d",ARGV0, str[i]);
}
}

str[j] = '\0'; // Null-terminate the string after removing control characters
}