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 memory leaks in write_c and eval_shell #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/shc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ int eval_shell(char * text)
i = sscanf(ptr, " #!%s%s %c", shll, opts, opts);
if (i < 1 || i > 2) {
fprintf(stderr, "%s: invalid first line in script: %s\n", my_name, ptr);
free(ptr);
return -1;
}
free(ptr);
Expand Down Expand Up @@ -1181,6 +1182,18 @@ void dump_array(FILE * o, void * ptr, char * name, int l, char * cast)
prnt_array(o, ptr, name, l, cast);
}

void cleanup_write_c(char* msg1, char* msg2, char* chk1, char* chk2, char* tst1, char* tst2, char* kwsh, char* name)
{
if (msg1) free(msg1);
if (msg2) free(msg2);
if (chk1) free(chk1);
if (chk2) free(chk2);
if (tst1) free(tst1);
if (tst2) free(tst2);
if (kwsh) free(kwsh);
if (name) free(name);
}

int write_C(char * file, char * argv[])
{
char pswd[256];
Expand Down Expand Up @@ -1234,6 +1247,7 @@ int write_C(char * file, char * argv[])
if (indx && key_with_file(kwsh)) {
fprintf(stderr, "%s: invalid file name: %s ", my_name, kwsh);
perror("");
cleanup_write_c(msg1, msg2, chk1, chk2, tst1, tst2, kwsh, name);
exit(1);
}
arc4(opts, opts_z); numd++;
Expand All @@ -1248,6 +1262,7 @@ int write_C(char * file, char * argv[])
if (!o) {
fprintf(stderr, "%s: creating output file: %s ", my_name, name);
perror("");
cleanup_write_c(msg1, msg2, chk1, chk2, tst1, tst2, kwsh, name);
exit(1);
}
fprintf(o, "#if 0\n");
Expand Down Expand Up @@ -1281,6 +1296,7 @@ int write_C(char * file, char * argv[])
indx = 0;
} while (!done);
} while (numd+=done);
cleanup_write_c(msg1, msg2, chk1, chk2, tst1, tst2, kwsh, name);
fprintf(o, "/* End of data[] */;\n");
fprintf(o, "#define %s_z %d\n", "hide", 1<<12);
fprintf(o, SETUID_line, SETUID_flag);
Expand Down