Skip to content
Closed
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
9 changes: 8 additions & 1 deletion Modules/_ssl/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ _PySSL_BytesFromBIO(_sslmodulestate *state, BIO *bio)
PyErr_SetString(PyExc_ValueError, "Not a memory BIO");
return NULL;
}
return PyBytes_FromStringAndSize(data, size);

PyBytesWriter *writer = PyBytesWriter_Create(size);
if (writer == NULL) {
return NULL;
}
char *str = PyBytesWriter_GetData(writer);
memcpy(str, data, size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, @vstinner,
Isn’t PyBytesWriter_WriteBytes not really intended for this use case? Looking at the current codebase, most cases seem to just use memcpy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think that this is not needed.

return PyBytesWriter_Finish(writer);
}

/* BIO_s_mem() to PyUnicode
Expand Down
Loading