On Sat, 7 Nov 2015, Conrad E. Meyer wrote:

Log:
 Flesh out sysctl types further (follow-up of r290475)

 Use the right intmax_t type instead of intptr_t in a few remaining
 places.

 Add support for CTLFLAG_TUN for the new fixed with types.  Bruce will be
 upset that the new handlers silently truncate tuned quad-sized inputs,
 but so do all of the existing handlers.

I think I have complained about the getenv_*() integer functions before.
All of them truncate or otherwise corrupt the value.  getenv_quad()
does non-blind clamping using strtoq() followed by blind scaling in
the suffix case.  All others use getenv_quad() with blind truncation,
except on 64-bit arches long == quad so getenv_long() only has the same
errors as getenv_quad().

Modified: head/sys/kern/kern_sysctl.c
==============================================================================
--- head/sys/kern/kern_sysctl.c Sat Nov  7 18:26:02 2015        (r290504)
+++ head/sys/kern/kern_sysctl.c Sat Nov  7 18:26:32 2015        (r290505)
...
+       case CTLTYPE_S32:
+               if (getenv_long(path + rem, &val_long) == 0)
+                       return;
+               val_32 = val_long;
+               req.newlen = sizeof(val_32);
+               req.newptr = &val_32;
+               break;

This should use getenv_int().  FreeBSD never supported 16-bit ints, and
POSIX now requires >= 32-bit ints.

@@ -250,6 +274,27 @@ sysctl_load_tunable_by_oid_locked(struct
                req.newlen = sizeof(val_64);
                req.newptr = &val_64;
                break;
+       case CTLTYPE_U8:
+               if (getenv_uint(path + rem, (unsigned int *)&val_int) == 0)
+                       return;
+               val_8 = val_int;
+               req.newlen = sizeof(val_8);
+               req.newptr = &val_8;
+               break;
+       case CTLTYPE_U16:
+               if (getenv_uint(path + rem, (unsigned int *)&val_int) == 0)
+                       return;
+               val_16 = val_int;
+               req.newlen = sizeof(val_16);
+               req.newptr = &val_16;
+               break;

These could use getenv_int() since int is larger than int17_t.  Will null
error checking, there would be little difference for the overflows caused
by negative values.  With non-null error checking, the checking would be
slightly different.

+       case CTLTYPE_U32:
+               if (getenv_ulong(path + rem, (unsigned long *)&val_long) == 0)
+                       return;
+               val_32 = val_long;
+               req.newlen = sizeof(val_32);
+               req.newptr = &val_32;
+               break;

Like for S32.

Bruce
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to