summaryrefslogtreecommitdiff
path: root/sys/kern/exec_script.c
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2018-09-03 16:29:22 +0000
committerriastradh <riastradh@NetBSD.org>2018-09-03 16:29:22 +0000
commita8a5c538b6388ff28a5944a8f637db644ee9a623 (patch)
tree4969c43ed378ff98e7f37be97a07b435cede6cb0 /sys/kern/exec_script.c
parentcc0f01d7332d63adc5489e77fd27e50767bcc316 (diff)
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name min/max should not silently truncate to 32 bits on 64-bit systems. This is purely a name change -- no functional change intended. HOWEVER! Some subsystems have #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) even though our standard name for that is MIN/MAX. Although these may invite multiple evaluation bugs, these do _not_ cause integer truncation. To avoid `fixing' these cases, I first changed the name in libkern, and then compile-tested every file where min/max occurred in order to confirm that it failed -- and thus confirm that nothing shadowed min/max -- before changing it. I have left a handful of bootloaders that are too annoying to compile-test, and some dead code: cobalt ews4800mips hp300 hppa ia64 luna68k vax acorn32/if_ie.c (not included in any kernels) macppc/if_gm.c (superseded by gem(4)) It should be easy to fix the fallout once identified -- this way of doing things fails safe, and the goal here, after all, is to _avoid_ silent integer truncations, not introduce them. Maybe one day we can reintroduce min/max as type-generic things that never silently truncate. But we should avoid doing that for a while, so that existing code has a chance to be detected by the compiler for conversion to uimin/uimax without changing the semantics until we can properly audit it all. (Who knows, maybe in some cases integer truncation is actually intended!)
Diffstat (limited to 'sys/kern/exec_script.c')
-rw-r--r--sys/kern/exec_script.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/kern/exec_script.c b/sys/kern/exec_script.c
index df7285d3120..749d39fce47 100644
--- a/sys/kern/exec_script.c
+++ b/sys/kern/exec_script.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_script.c,v 1.77 2018/06/30 11:10:54 kre Exp $ */
+/* $NetBSD: exec_script.c,v 1.78 2018/09/03 16:29:35 riastradh Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.77 2018/06/30 11:10:54 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.78 2018/09/03 16:29:35 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_script.h"
@@ -145,7 +145,7 @@ exec_script_makecmds(struct lwp *l, struct exec_package *epp)
* Check that the shell spec is terminated by a newline, and that
* it isn't too large.
*/
- hdrlinelen = min(epp->ep_hdrvalid, SCRIPT_HDR_SIZE);
+ hdrlinelen = uimin(epp->ep_hdrvalid, SCRIPT_HDR_SIZE);
for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; cp < hdrstr + hdrlinelen;
cp++) {
if (*cp == '\n') {