tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: *oldlenp comes back with wrong value in helper sysctl_createv() function



On Sat, Jan 20, 2024 at 10:48:12AM +0100, Emile 'iMil' Heitor wrote:


Hi,

that's from sysctl.c:

        case CTLTYPE_STRING: {
                unsigned char buf[1024], *tbuf;
                tbuf = buf;
                sz = sizeof(buf); 
                rc = prog_sysctl(&name[0], namelen, tbuf, &sz, NULL, 0);

The sysctl command first tries with a buffer of 1024 bytes
and retries with the right size when that was too small.

Compared to "probing" with a NULL buffer this saves a round trip
to the kernel for most sysctls.

A simple helper function would always return the needed size and only
copy out when oldp was set. sysctl will check the returned *oldlenp 
against the value passed by the caller and return ENOMEM as appropriate.


Greetings,
-- 
                                Michael van Elst
Internet: mlelstv%serpens.de@localhost
                                "A potential Snark may lurk in every tree."


Home | Main Index | Thread Index | Old Index