-
Notifications
You must be signed in to change notification settings - Fork 66
Outstanding fixes for production use of liblognorm (segfault, memory leak) and issues cleanup following 2.0.7 #380
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: stable
Are you sure you want to change the base?
Conversation
In struct data_String, the perm_chars member is declared as
an array indexed from 0 to 255:
char perm_chars[256];
Bytes > 127, for instance with UTF-8 data, cause a segfault.
I believe casting as (unsigned char) instead of (unsigned) should
ensure the perm_chars is accessed at index 0..255.
I came this segfault with the following string sample. Rsyslog crashes
in stringIsPermittedChar() when it processes char byte 0xe2.
echo 'd’ouverture' |od -t x1 -a
0000000 64 e2 80 99 6f 75 76 65 72 74 75 72 65 0a
d b nul em o u v e r t u r e nl
0000016
Note line numbers in parser.c reported by gdb are wrong with master
because it is from a 2.0.6 version with other patches:
#0 0x00007f9a73034713 in stringIsPermittedChar (data=0x55bd3a1a42a0, c=-30 '\342') at parser.c:3236
rsyslog#1 0x00007f9a73034c63 in ln_v2_parseString (npb=0x7f9a5292d670, offs=0x7f9a5292d600, pdata=0x55bd3a1a42a0, parsed=0x7f9a5292d5f8, value=0x7f9a5292d5f0) at parser.c:3363
rsyslog#2 0x00007f9a73029279 in tryParser (npb=0x7f9a5292d670, dag=0x55bd3a1a11a0, offs=0x7f9a5292d600, pParsed=0x7f9a5292d5f8, value=0x7f9a5292d5f0, prs=0x55bd3a14ea00) at pdag.c:1454
rsyslog#3 0x00007f9a730295db in ln_normalizeRec (npb=0x7f9a5292d670, dag=0x55bd3a1a11a0, offs=0, bPartialMatch=0, json=0x7f9a4c4dd260, endNode=0x7f9a5292d6a0) at pdag.c:1575
rsyslog#4 0x00007f9a730299ac in ln_normalize (ctx=0x55bd3a14e680, str=0x7f9a4c4e19a0 "d’ouverture de session :rsyslog#11#011{837B856E-32B3-78E2-3D77-4E95F8904E71}rsyslog#15#012#015#012Informations sur le processus :rsyslog#15#012#011ID du processus :rsyslog#11#0110x0#015#012#011Nom du processus :rsyslog#11#01"..., strLen=8021, json_p=0x7f9a5292d6d8) at pdag.c:1653
rsyslog#5 0x00007f9a7302459e in doAction (pMsgData=0x7f9a5292d740, pWrkrData=0x7f9a4c4daad0) at mmnormalize.c:259
...
This should fix issue rsyslog#340 "UTF-8 accentuated
characters causing segfault". The patch in this pull request is
also similar.
Summary of ChangesHello @julthomas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the stability and reliability of Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request addresses critical issues in liblognorm, specifically a memory leak and a potential segfault, along with a cleanup of issues following the 2.0.7 release. The changes include a fix for a memory leak when a custom type in rules does not match and a fix for an out-of-bounds access in perm_chars causing a segfault. The review focuses on the correctness and security aspects of these changes.
| if (r != 0) { | ||
| json_object_put(*value); | ||
| *value = NULL; |
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.
When a custom parser fails (r != 0), the json_object pointed to by *value is freed, and *value is set to NULL. This is important to prevent memory leaks and ensure that the caller does not attempt to use a dangling pointer. Failing to do so could lead to memory corruption and program instability.
It's crucial to handle the error case where the custom parser fails to prevent memory leaks.
json_object_put(*value);
*value = NULL;|
thx, I'll have a more detailled look later this week. If you do not hear anything substantial after the weekend, I would appreciate a ping (but no force, would just be nice!). |
Hello @rgerhards,
As discussed on ML and private, here is a branch that contains 2 patches criticals for our production. This PR is aligned with current stable branch (2.0.7). Patches will apply on current master as well.
fix memory leak when a custom type in rules does not match(@merics) should closestring: fix out of bound access in perm_chars causing segfault(@julthomas) should closeFollowing 2.0.7 release, I believe a number of issues or PR could be closed (there are probably more). A cleanup would not harm.