ioctl request type should be unsigned long
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Summary: sb-unix:unix-ioctl uses a signed int as the ioctl request's type. This should be an unsigned long.
To reproduce: (sb-unix:unix-ioctl 0 (expt 2 31) nil)
Patch included.
The ioctl specification, insofar as it exists,[1] specifies the request type to be unsigned long.
Currently sbcl declares a (signed-byte 32), and uses the sb-alien C-type export of int. sb-alien uses a (signed-byte 32) for this, as ints in C are signed by default when no sign is declared.
This results in an error when ioctl commands larger than 2^31 are issued. For example, accessing SPI hardware registers on the Raspberry Pi requires commands larger than 2^31.[2]
It looks like at some point (15 years ago)[3] this argument type changed from signed-int to int, though as far as I understand removing the "signed" does not turn it into an unsigned integer.
Using unsigned-long as the type matches the ioctl specification, and works on my system. I don't know if this would break any currently existing programs, or if the cmd argument of unix-ioctl will get cast automatically in most cases.
(Without this patch, currently a workaround is possible by calling sb-unix:unix-ioctl with a negative number that then later gets interpreted as unsigned int. It's kinda ugly.[4])
[1] http://
[2] https:/
[3] https:/
[4] https:/
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
Patch as attachment.