Skip to content

[3.13] gh-123919: Fix null handling in _freeze_module.c (GH-123920) #123948

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

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
11 changes: 11 additions & 0 deletions Programs/_freeze_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ static PyObject *
compile_and_marshal(const char *name, const char *text)
{
char *filename = (char *) malloc(strlen(name) + 10);
if (filename == NULL) {
return PyErr_NoMemory();
}
sprintf(filename, "<frozen %s>", name);
PyObject *code = Py_CompileStringExFlags(text, filename,
Py_file_input, NULL, 0);
Expand All @@ -133,6 +136,9 @@ get_varname(const char *name, const char *prefix)
{
size_t n = strlen(prefix);
char *varname = (char *) malloc(strlen(name) + n + 1);
if (varname == NULL) {
return NULL;
}
(void)strcpy(varname, prefix);
for (size_t i = 0; name[i] != '\0'; i++) {
if (name[i] == '.') {
Expand Down Expand Up @@ -178,6 +184,11 @@ write_frozen(const char *outpath, const char *inpath, const char *name,

fprintf(outfile, "%s\n", header);
char *arrayname = get_varname(name, "_Py_M__");
if (arrayname == NULL) {
fprintf(stderr, "memory error: could not allocate varname\n");
fclose(outfile);
return -1;
}
write_code(outfile, marshalled, arrayname);
free(arrayname);

Expand Down
Loading