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

Rsyslog run into segfault due to processing malform queue message. #5365

Open
lonicerae opened this issue Apr 16, 2024 · 2 comments
Open

Rsyslog run into segfault due to processing malform queue message. #5365

lonicerae opened this issue Apr 16, 2024 · 2 comments
Assignees
Labels

Comments

@lonicerae
Copy link
Contributor

Hello,

When I was researching a segfault issue of the rsyslog, I found that the a malformed queue message could make the message parser quit with RS_RET_INVALID_DELIMITER. Later the the rsCStrDestruct() would try to free the buffer address in which no allocated string was assigned. The flow looks like this:

 500 /* de-serialize a string, length must be provided but may be 0 */
 501 static rsRetVal objDeserializeStr(cstr_t **ppCStr, int iLen, strm_t *pStrm)
 502 {
 503         DEFiRet;
 504         int i;
 505         uchar c;
 506         cstr_t *pCStr = NULL;
 507 
 508         assert(ppCStr != NULL);
 509         assert(iLen >= 0);
 510 
 511         CHKiRet(cstrConstruct(&pCStr));
 512 
 513         NEXTC;
 514         for(i = 0 ; i < iLen ; ++i) {
 515                 CHKiRet(cstrAppendChar(pCStr, c));
 516                 NEXTC;
 517         }
 518         cstrFinalize(pCStr);
 519 
 520         /* check terminator */
 521         if(c != ':') ABORT_FINALIZE(RS_RET_INVALID_DELIMITER);
 522 
 523         *ppCStr = pCStr; <<<--------- Not allocated.

==>

1304 rsRetVal
1305 MsgDeserialize(smsg_t * const pMsg, strm_t *pStrm)
1306 {
:
1449 finalize_it:
1450         if(pVar != NULL)
1451                 var.Destruct(&pVar);

==>

220 void rsCStrDestruct(cstr_t **const ppThis)
221 {
222         free((*ppThis)->pBuf); <<<--------- Try to free and run into segfault
223         RSFREEOBJ(*ppThis);
224         *ppThis = NULL;
225 }

Perhaps we need to strengthen the destruction functions to cope with the bad queue messages.

Best regards,
Flos

@rgerhards rgerhards self-assigned this Apr 16, 2024
@rgerhards rgerhards added the bug label Apr 16, 2024
@rgerhards
Copy link
Member

thx for the info, much appreciated!

@lonicerae
Copy link
Contributor Author

Hi @rgerhards , just proposed a fix here:

Please help to review it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants