Sunday, October 03, 2021

Inconsistent behavior of sysctl(2) for some MIB paths?

Hi all,

I think I found some cases where the "oldlenp" value is not properly
updated according to the details in the manual page. In particular
this section from sysctl(2):

The size of the available data can be determined by calling sysctl() with
a NULL parameter for oldp. The size of the available data will be
returned in the location pointed to by oldlenp.

This seems to work fine for most cases, but when testing the program
below I found that for some MIB paths, the oldlenp value is not
updated.

System details: OpenBSD 6.9, amd64, with all patches applied via syspatch

---8<----
#include <stdio.h>

#include <sys/queue.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>

int main(int argc, char **argv)
{
#if 1
/* working case, prints: "r: 0, len: 4" */
int path[] = { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_SYN_HASH_SIZE };
#else
/* failing case, prints: "r: 0, len: 0" */
int path[] = { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_BADDYNAMIC };

No comments:

Post a Comment