Skip to content

Commit d0f020f

Browse files
renatoalencarRenato Alencar
authored and
Renato Alencar
committed
gh-113078: Use uint64 for dev_t and uint32 for make params
Following the implementions from both FreeBSD and GNU glibc, `PyLong_FromDev should actually be unsigned. This can break on FreeBSD systems using ZFS, since they wouldn't generate device IDs with 56 upper bits randomly, therefore the MSB too. Also, following the documentation from FreeBSD and Linux, `makedev` should accept unsigned 32 bit integers. The reason to that is because on FreeBSD `major` and `minor` can return anything on the 32 bit int range and on Linux it really specifies that it returns a unsigned integer.
1 parent fddc829 commit d0f020f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

Modules/clinic/posixmodule.c.h

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ _Py_Gid_Converter(PyObject *obj, gid_t *p)
934934
#endif /* MS_WINDOWS */
935935

936936

937-
#define _PyLong_FromDev PyLong_FromLongLong
937+
#define _PyLong_FromDev PyLong_FromUnsignedLongLong
938938

939939

940940
#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) || defined(HAVE_DEVICE_MACROS)
@@ -12040,16 +12040,16 @@ os_minor_impl(PyObject *module, dev_t device)
1204012040
/*[clinic input]
1204112041
os.makedev -> dev_t
1204212042
12043-
major: int
12044-
minor: int
12043+
major: unsigned_int
12044+
minor: unsigned_int
1204512045
/
1204612046
1204712047
Composes a raw device number from the major and minor device numbers.
1204812048
[clinic start generated code]*/
1204912049

1205012050
static dev_t
12051-
os_makedev_impl(PyObject *module, int major, int minor)
12052-
/*[clinic end generated code: output=881aaa4aba6f6a52 input=4b9fd8fc73cbe48f]*/
12051+
os_makedev_impl(PyObject *module, unsigned int major, unsigned int minor)
12052+
/*[clinic end generated code: output=19d6d22807bf0d20 input=27d2f0106009da11]*/
1205312053
{
1205412054
return makedev(major, minor);
1205512055
}

0 commit comments

Comments
 (0)