Skip to content

fix(omsentinel): multiple fixes and cleanup - #26

Merged
frikilax merged 0 commit into
devfrom
omsentinel-multiple-issues
Jun 15, 2026
Merged

fix(omsentinel): multiple fixes and cleanup#26
frikilax merged 0 commit into
devfrom
omsentinel-multiple-issues

Conversation

@Kira-vspec

Copy link
Copy Markdown

Summary

This PR introduces several fixes and improvements to the omsentinel module,
focusing on memory management, resource handling, and overall stability. It also improves the clarity of error logs.

In this PR, each commit targets a specific fix.

Comment thread plugins/omsentinel/omsentinel.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there a control problem with the number of bytes received? and the fact that contents may not be NULL terminated?

Comment thread plugins/omsentinel/omsentinel.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this value should be saved along authReply, and used for all manipulations of the variable (especially in loggers and curlAuth())

curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code != 200)
{
dbgprintf("omsentinel: http_reply_code=%ld \n", http_code);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dbgprintf("omsentinel: http_reply_code=%ld \n", http_code);
LogError(0, RS_RET_SUSPENDED, "omsentinel[curlAuth]: http_reply_code=%ld", http_code);

res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
LogError(0, RS_RET_ERR, "curl: error: %s\n", curl_easy_strerror(res));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LogError(0, RS_RET_ERR, "curl: error: %s\n", curl_easy_strerror(res));
LogError(0, RS_RET_SUSPENDED, "omsentinel[curlAuth]: error: %s", curl_easy_strerror(res));

if(!(pData->token = (uchar *)strdup(tokenStr)))
{
LogError(0, RS_RET_OUT_OF_MEMORY,
"omsentinel: could not allocate Bearer token \n");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"omsentinel[curlAuth]: could not allocate Bearer token");

ABORT_FINALIZE(RS_RET_SUSPENDED);
}
json_object_put(parsed_json);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}
else
{
LogError(0, RS_RET_SUSPENDED, "omsentinel[curlAuth]: Could not decode a valid JSON in reply");
ABORT_FINALIZE(RS_RET_SUSPENDED);
}

}
else
{
LogError(0, RS_RET_OUT_OF_MEMORY, "omsentinel: could not allocate http response \n");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LogError(0, RS_RET_OUT_OF_MEMORY, "omsentinel[curlAuth]: could not allocate http response");

// httpHeader
if (asprintf((char **)&pData->httpHeader, (char *)pData->authorizationHeader, pData->token) < 0)
{
LogError(0, RS_RET_OUT_OF_MEMORY, "omsentinel: cannot allocate memory for http header\n");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LogError(0, RS_RET_OUT_OF_MEMORY, "omsentinel[curlAuth]: cannot allocate memory for http header");

Comment thread plugins/omsentinel/omsentinel.c Outdated
if (pData->httpHeader)
{
free(pData->httpHeader);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those variables are relative to the instance, so they can be accessed by several workers at once
I believe:

  • the values should be protected by a mutex
  • or the values could be relative to the worker (meaning = 1 token per worker = more authentication requests! So maybe not advisable)

Comment thread plugins/omsentinel/omsentinel.c Outdated

if (pData->token && pData->dce && pData->dcr && pData->stream_name)
// Before building batch check/regenerate auths
CHKiRet(initAuth(pWrkrData));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after reflecting on the code, it seems there is a deep misunderstanding (or misuse) of transactions and the doAction macro.

  1. I believe doAction should tell rsyslog how to handle the current transaction (send, keep, drop, etc... see RS_RET_DEFER_COMMIT in rsyslog.h)
  2. Handling of current authentication could be moved to the endTransaction transaction (if transactions were correctly used), when submitBatch() would be used (and it would be the only call to the function)

@frikilax
frikilax merged commit 5f78485 into dev Jun 15, 2026
8 of 25 checks passed
@ELDiablO59152
ELDiablO59152 deleted the omsentinel-multiple-issues branch June 15, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants