mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-115886: Handle embedded null characters in shared memory name (GH-115887)
shm_open() and shm_unlink() now check for embedded null characters in the name and raise an error instead of silently truncating it.
This commit is contained in:
parent
5770006ffa
commit
79811ededd
3 changed files with 31 additions and 3 deletions
|
@ -11,6 +11,7 @@ posixshmem - A Python extension that provides shm_open() and shm_unlink()
|
|||
|
||||
#include <Python.h>
|
||||
|
||||
#include <string.h> // strlen()
|
||||
#include <errno.h> // EINTR
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
# include <sys/mman.h> // shm_open(), shm_unlink()
|
||||
|
@ -48,10 +49,15 @@ _posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
|
|||
{
|
||||
int fd;
|
||||
int async_err = 0;
|
||||
const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
|
||||
Py_ssize_t name_size;
|
||||
const char *name = PyUnicode_AsUTF8AndSize(path, &name_size);
|
||||
if (name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (strlen(name) != (size_t)name_size) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return -1;
|
||||
}
|
||||
do {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
fd = shm_open(name, flags, mode);
|
||||
|
@ -87,10 +93,15 @@ _posixshmem_shm_unlink_impl(PyObject *module, PyObject *path)
|
|||
{
|
||||
int rv;
|
||||
int async_err = 0;
|
||||
const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
|
||||
Py_ssize_t name_size;
|
||||
const char *name = PyUnicode_AsUTF8AndSize(path, &name_size);
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (strlen(name) != (size_t)name_size) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return NULL;
|
||||
}
|
||||
do {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
rv = shm_unlink(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue