Skip to content

Commit 24be4b8

Browse files
committed
gh-101703: Use bounded formatting in mmap.set_name()
1 parent f18fb83 commit 24be4b8

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎Modules/mmapmodule.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,14 +1128,13 @@ mmap_mmap_set_name_impl(mmap_object *self, const char *name)
11281128
/*[clinic end generated code: output=1edaf4fd51277760 input=7c0e2a17ca6d1adc]*/
11291129
{
11301130
#if defined(MAP_ANONYMOUS) && defined(__linux__)
1131-
const char *prefix = "cpython:mmap:";
1132-
if (strlen(name) + strlen(prefix) > 79) {
1131+
char buf[80];
1132+
int len = PyOS_snprintf(buf, sizeof(buf), "cpython:mmap:%s", name);
1133+
if (len < 0 || (size_t)len >= sizeof(buf)) {
11331134
PyErr_SetString(PyExc_ValueError, "name is too long");
11341135
return NULL;
11351136
}
11361137
if (self->flags & MAP_ANONYMOUS) {
1137-
char buf[80];
1138-
sprintf(buf, "%s%s", prefix, name);
11391138
if (_PyAnnotateMemoryMap(self->data, self->size, buf) < 0) {
11401139
PyErr_SetFromErrno(PyExc_OSError);
11411140
return NULL;

0 commit comments

Comments
 (0)