Skip to content

Commit

Permalink
[3.13] gh-123919: Fix null handling in _freeze_module.c (GH-123920) (
Browse files Browse the repository at this point in the history
…#123948)

gh-123919: Fix null handling in `_freeze_module.c` (GH-123920)
(cherry picked from commit c8d1dbe)

Co-authored-by: sobolevn <mail@sobolevn.me>
  • Loading branch information
miss-islington and sobolevn authored Sep 30, 2024
1 parent 793cb77 commit 8b9bd43
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 8b9bd43

Please sign in to comment.