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

[FIXED] microService_AddEndpoint() could crash if subject is invalid #831

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ micro_add_endpoint(microEndpoint **new_ep, microService *m, microGroup *g, micro
return microError_Wrapf(err, "failed to create full subject for endpoint '%s'", cfg->Name);
if (!micro_is_valid_subject(fullSubject))
{
err = microError_Wrapf(micro_ErrorInvalidArg, "invalid subject '%s' for endpoint '%s'", fullSubject, cfg->Name);
NATS_FREE(fullSubject);
return microError_Wrapf(micro_ErrorInvalidArg, "invalid subject '%s' for endpoint '%s'", fullSubject, cfg->Name);
return err;
}

_lock_service(m);
Expand Down
8 changes: 8 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33940,6 +33940,7 @@ void test_MicroGroups(void)
microGroup *g2 = NULL;
microServiceInfo *info = NULL;
int i;
char buf[1024];

microEndpointConfig ep2_cfg = {
.Name = "ep2",
Expand Down Expand Up @@ -33977,6 +33978,13 @@ void test_MicroGroups(void)

_startMicroservice(&m, nc, &cfg, NULL, 0, &arg);

test("AddEnpoint with invalid subject: ");
microEndpointConfig invalid_subject_ep_cfg = { .Name = "invalidsubject", .Handler = _microHandleRequest42, .Subject = "foo bar" };
err = microService_AddEndpoint(m, &invalid_subject_ep_cfg);
testCond((err != NULL) && (strstr(microError_String(err, buf, sizeof(buf)), "invalid subject 'foo bar'") != NULL));
microError_Destroy(err);
err = NULL;

test("AddEndpoint 1 to service: ");
microEndpointConfig ep1_cfg = { .Name = "ep1", .Handler = _microHandleRequest42 };
testCond(NULL == microService_AddEndpoint(m, &ep1_cfg));
Expand Down
Loading