Skip to content

Commit 366fc25

Browse files
sobolevnmiss-islington
authored andcommitted
pythongh-123919: Fix null handling in _freeze_module.c (pythonGH-123920)
(cherry picked from commit c8d1dbe) Co-authored-by: sobolevn <[email protected]>
1 parent 660baa1 commit 366fc25

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Programs/_freeze_module.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ static PyObject *
110110
compile_and_marshal(const char *name, const char *text)
111111
{
112112
char *filename = (char *) malloc(strlen(name) + 10);
113+
if (filename == NULL) {
114+
return PyErr_NoMemory();
115+
}
113116
sprintf(filename, "<frozen %s>", name);
114117
PyObject *code = Py_CompileStringExFlags(text, filename,
115118
Py_file_input, NULL, 0);
@@ -133,6 +136,9 @@ get_varname(const char *name, const char *prefix)
133136
{
134137
size_t n = strlen(prefix);
135138
char *varname = (char *) malloc(strlen(name) + n + 1);
139+
if (varname == NULL) {
140+
return NULL;
141+
}
136142
(void)strcpy(varname, prefix);
137143
for (size_t i = 0; name[i] != '\0'; i++) {
138144
if (name[i] == '.') {
@@ -178,6 +184,11 @@ write_frozen(const char *outpath, const char *inpath, const char *name,
178184

179185
fprintf(outfile, "%s\n", header);
180186
char *arrayname = get_varname(name, "_Py_M__");
187+
if (arrayname == NULL) {
188+
fprintf(stderr, "memory error: could not allocate varname\n");
189+
fclose(outfile);
190+
return -1;
191+
}
181192
write_code(outfile, marshalled, arrayname);
182193
free(arrayname);
183194

0 commit comments

Comments
 (0)