Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix #4 #5

wants to merge 1 commit into from

Conversation

LdBeth
Copy link

@LdBeth LdBeth commented Dec 18, 2021

oldlenp was not correctly initialized according to man 3 sysctl.

The information is copied into the buffer specified by oldp. The size of
the buffer is given by the location specified by oldlenp before the call,
and that location gives the amount of data copied after a successful call
and after a call that returns with the error code ENOMEM.

This should fix the problem on macOS/OS X, and potentially other BSDs.

`oldlenp` was not correctly initialized according to `man 3 sysctl`
@CatherineTower
Copy link

CatherineTower commented Feb 10, 2022

This will work, but at least on FreeBSD hw.ncpu is currently specified to return an int, not a uint. There is also theoretically a potential buffer overflow vulnerability if you only allocate a single int for oldp; the number of elements -- that is, the value that goes in oldlenp -- is put there by a sysctl call where oldp is null, and you can use that number to allocate space for oldp. Because of this, I'd recommend something like:

(cffi:with-foreign-object (oldlenp :size)
      (sysctl name-pointer 2 (cffi:null-pointer) oldlenp (cffi:null-pointer) 0)
      (cffi:with-foreign-object (oldp :int (cffi:mem-ref oldlenp :size))
        (let ((result (sysctl name-pointer 2 oldp oldlenp (cffi:null-pointer) 0)))

From a practical standpoint, the above almost definitely isn't necessary, it's a mostly safe assumption that the result will fit in a single int. But the above conforms to the sysctl documentation on FreeBSD

The change also makes CL-CPUS work under CCL and ECL on FreeBSD, by my testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants