-
-
Notifications
You must be signed in to change notification settings - Fork 126
sys-log: log filter #634
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
base: main
Are you sure you want to change the base?
sys-log: log filter #634
Conversation
qubes-rpc/vm-log.c
Outdated
| /** | ||
| * Implements strict ASCII filtering and replaces non-printable control characters. | ||
| * All bytes outside the standard ASCII range (0x00 - 0x7F) are replaced with '?'. | ||
| * Control characters (0x00-0x1F) and DEL (0x7F) are replaced with ' '. | ||
| * | ||
| * @param str Input string (read-only) | ||
| * @param result Buffer to store the sanitized output (must be large enough) | ||
| * @param max_len Maximum length of the input string to process | ||
| * @return The length of the sanitized string written to result | ||
| */ | ||
| size_t filter_to_ascii_and_sanitize(const char *str, char *result, size_t max_len) { | ||
| size_t i; | ||
| size_t j = 0; | ||
|
|
||
| for (i = 0; i < max_len && str[i] != '\0'; i++) { | ||
| unsigned char byte = (unsigned char)str[i]; | ||
|
|
||
| if (byte > 0x7F) { | ||
| result[j++] = '?'; | ||
| continue; | ||
| } | ||
|
|
||
| // Replace harmful control characters (0x00-0x1F) and DEL (0x7F) | ||
| if ((byte < 0x20) || byte == 0x7F) { | ||
| result[j++] = ' '; | ||
| } | ||
| // Keep printable ASCII characters | ||
| else { | ||
| result[j++] = str[i]; | ||
| } | ||
| } | ||
| result[j] = '\0'; | ||
| return j; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See libqubes-pure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, maybe limiting chars to only ASCII here was a bit paranoid. I'll move this function to qubes-linux-utils and extend the restrictions for better handling of utf.
A simple and efficient log sanitizer, ready to work with rsyslog
first step in: QubesOS/qubes-issues/issues/830
requires: QubesOS/qubes-linux-utils/pull/136