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

Remove 1KB stack buffer from _dmalloc_environ_process #74

Merged
merged 1 commit into from
Apr 18, 2021
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
24 changes: 10 additions & 14 deletions env.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void _dmalloc_address_break(const char *addr_all, DMALLOC_PNT *addr_p,
/*
* Break up START_ALL into SFILE_P, SLINE_P, and SCOUNT_P
*/
void _dmalloc_start_break(char *start_all, char **start_file_p,
void _dmalloc_start_break(const char *start_all, char **start_file_p,
int *start_line_p, unsigned long *start_iter_p,
unsigned long *start_size_p)
{
Expand Down Expand Up @@ -208,8 +208,7 @@ void _dmalloc_environ_process(const char *env_str, DMALLOC_PNT *addr_p,
unsigned long *start_size_p,
unsigned long *limit_p)
{
char *env_p, *this_p;
char buf[1024];
const char *env_p, *this_p;
int len, done_b = 0;
unsigned int flags = 0;
attr_t *attr_p;
Expand All @@ -226,20 +225,16 @@ void _dmalloc_environ_process(const char *env_str, DMALLOC_PNT *addr_p,
SET_POINTER(start_size_p, 0);
SET_POINTER(limit_p, 0);

/* make a copy */
(void)strncpy(buf, env_str, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';

/* handle each of tokens, in turn */
for (env_p = buf, this_p = buf; ! done_b; env_p++, this_p = env_p) {
for (env_p = env_str, this_p = env_str; ! done_b; env_p++, this_p = env_p) {

/* find the comma of end */
for (;; env_p++) {
if (*env_p == '\0') {
done_b = 1;
break;
}
if (*env_p == ',' && (env_p == buf || *(env_p - 1) != '\\')) {
if (*env_p == ',' && (env_p == env_str || *(env_p - 1) != '\\')) {
break;
}
}
Expand All @@ -250,8 +245,6 @@ void _dmalloc_environ_process(const char *env_str, DMALLOC_PNT *addr_p,
continue;
}

*env_p = '\0';

len = strlen(ADDRESS_LABEL);
if (strncmp(this_p, ADDRESS_LABEL, len) == 0
&& *(this_p + len) == ASSIGNMENT_CHAR) {
Expand Down Expand Up @@ -289,8 +282,9 @@ void _dmalloc_environ_process(const char *env_str, DMALLOC_PNT *addr_p,
if (strncmp(this_p, LOGFILE_LABEL, len) == 0
&& *(this_p + len) == ASSIGNMENT_CHAR) {
this_p += len + 1;
(void)strncpy(log_path, this_p, sizeof(log_path));
log_path[sizeof(log_path) - 1] = '\0';
len = MIN(env_p - this_p, sizeof(log_path));
(void)strncpy(log_path, this_p, len);
log_path[len - 1] = '\0';
SET_POINTER(logpath_p, log_path);
continue;
}
Expand Down Expand Up @@ -318,8 +312,10 @@ void _dmalloc_environ_process(const char *env_str, DMALLOC_PNT *addr_p,
}

/* need to check the short/long debug options */
len = env_p - this_p;
for (attr_p = attributes; attr_p->at_string != NULL; attr_p++) {
if (strcmp(this_p, attr_p->at_string) == 0) {
if (len == strlen(attr_p->at_string) &&
strncmp(this_p, attr_p->at_string, len) == 0) {
flags |= attr_p->at_value;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion env.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void _dmalloc_address_break(const char *addr_all, DMALLOC_PNT *addr_p,
* Break up START_ALL into SFILE_P, SLINE_P, and SCOUNT_P
*/
extern
void _dmalloc_start_break(char *start_all, char **start_file_p,
void _dmalloc_start_break(const char *start_all, char **start_file_p,
int *start_line_p, unsigned long *start_iter_p,
unsigned long *start_size_p);

Expand Down