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 the set_sec_mod handler #1276

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -5539,6 +5539,7 @@ static int set_sec_mod_handler(ldmsd_req_ctxt_t reqc)
if (isdigit(value[0])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nichamon the value variable here is leaked throughout this function. Although it is freed at the end, because it is reused throughout, only the last value is actually freed. This fix is part of the "memory-leak" branch I was going to send you, but I think my change and yours will conflict. Maybe I just send you the branch and you combine them all into one pull request that you submit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll do that.

uid = strtol(value, &endptr, 0);
if (uid < 0) {
reqc->errcode = EINVAL;
(void) snprintf(reqc->line_buf, reqc->line_len,
"The given UID '%s' is invalid.",
value);
Expand All @@ -5547,6 +5548,7 @@ static int set_sec_mod_handler(ldmsd_req_ctxt_t reqc)
} else {
struct passwd *pwd = getpwnam(value);
if (!pwd) {
reqc->errcode = EINVAL;
(void)snprintf(reqc->line_buf, reqc->line_len,
"Unknown user '%s'", value);
goto free_regex;
Expand All @@ -5561,6 +5563,7 @@ static int set_sec_mod_handler(ldmsd_req_ctxt_t reqc)
if (isdigit(value[0])) {
gid = strtol(value, &endptr, 0);
if (gid < 0) {
reqc->errcode = EINVAL;
(void) snprintf(reqc->line_buf, reqc->line_len,
"The given GID '%s' is invalid.",
value);
Expand All @@ -5569,8 +5572,10 @@ static int set_sec_mod_handler(ldmsd_req_ctxt_t reqc)
} else {
struct group *grp = getgrnam(value);
if (!grp) {
reqc->errcode = EINVAL;
(void) snprintf(reqc->line_buf, reqc->line_len,
"Unknown group '%s'", value);
goto free_regex;
}
gid = grp->gr_gid;
}
Expand Down