Skip to content

Commit ef08463

Browse files
committed
gh-139156: Use PyBytesWriter in _PySSL_BytesFromBIO
1 parent c4f21d7 commit ef08463

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Modules/_ssl/misc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ _PySSL_BytesFromBIO(_sslmodulestate *state, BIO *bio)
1515
PyErr_SetString(PyExc_ValueError, "Not a memory BIO");
1616
return NULL;
1717
}
18-
return PyBytes_FromStringAndSize(data, size);
18+
19+
PyBytesWriter *writer = PyBytesWriter_Create(size);
20+
if (writer == NULL) {
21+
return NULL;
22+
}
23+
char *str = PyBytesWriter_GetData(writer);
24+
memcpy(str, data, size);
25+
return PyBytesWriter_Finish(writer);
1926
}
2027

2128
/* BIO_s_mem() to PyUnicode

0 commit comments

Comments
 (0)