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

Fix possible null deref in pub #848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wooffie
Copy link
Contributor

@wooffie wooffie commented Feb 21, 2025

  1. remove reply construct because it is done by natsConn_publish

    reply = msg->reply;

  2. we have check msg != NULL and i just move it to natsConn_publish

    const char *reply = (msg != NULL ? msg->reply : NULL);

src/pub.c Outdated
@@ -67,7 +67,7 @@ natsConn_publish(natsConnection *nc, natsMsg *msg, const char *reply, bool direc
int hdrl = 0;
int totalLen = 0;

if (nc == NULL)
if (nc == NULL || msg == NULL)
Copy link
Member

Choose a reason for hiding this comment

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

No, because normally the caller ensures that it is not NULL. The only exception was natsConnection_PublishMsg() that needs fixing.

The rationale is that this is an internal function and if the caller guarantees that the message is not NULL, then we should not check in this one, which makes it redundant. In lots of places, the caller uses a stack variable and it will never be NULL.

@@ -279,10 +279,9 @@ natsConnection_PublishString(natsConnection *nc, const char *subj,
natsStatus
natsConnection_PublishMsg(natsConnection *nc, natsMsg *msg)
{
const char *reply = (msg != NULL ? msg->reply : NULL);
Copy link
Member

Choose a reason for hiding this comment

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

We need to rewrite this function and if msg == NULL return an invalid arg. The check of nc is done in the lower function, but could easily be added into this one.

As for removing the reply subject, of course we need it, but yes, the called function will take it from the provided message structure if not provided as a parameter, so I guess this change is ok.

Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM

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