ioctl request type should be unsigned long

Bug #1746619 reported by Marius van Voorden
6
This bug affects 1 person
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://man7.org/linux/man-pages/man2/ioctl.2.html
[2] https://github.com/Shinmera/cl-spidev/blob/master/constants.lisp
[3] https://github.com/sbcl/sbcl/commit/0677c33068646b6ec33d5f622771673f3de38504#diff-e32cce0bfb6cd207741f69a9af4a57ce
[4] https://github.com/Shinmera/cl-spidev/commit/8b524a533d9cc52c57b9fae34c9b9d3f46385ef0

Revision history for this message
Marius van Voorden (mqrius) wrote :

Patch as attachment.

description: updated
Revision history for this message
Stas Boukarev (stassats) wrote :

a) The patch doesn't apply.
b) The lisp declaration is still saying "32".
c) You shouldn't be using sb-unix:unix-ioctl at all, it's internal. Use sb-posix:ioctl, but it also uses int.

I fixed both sb-unix and sb-posix in 6a17b926afcfeea8781a328b0951aa552c96fb18

Changed in sbcl:
status: New → Fix Committed
Stas Boukarev (stassats)
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.