From 7b2c2c925bce647de68993e45d20ddf15e67bae4 Mon Sep 17 00:00:00 2001 From: bluhm Date: Fri, 12 Apr 2024 14:17:42 +0000 Subject: [PATCH] In snmpd_metrics process keep file descriptors 0 1 2 open. stdin, stdout, stderr are reserverd. They should point to a terminal, a redirect file or pipe, or /dev/null. Closing them and allocating arbitrary files in those places is not good. Call closefrom with 4 to keep /dev/null open in snmpd_metrics. OK martijn@ --- usr.sbin/snmpd/snmpd.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/usr.sbin/snmpd/snmpd.c b/usr.sbin/snmpd/snmpd.c index c48b2a959d6..60af191fb6f 100644 --- a/usr.sbin/snmpd/snmpd.c +++ b/usr.sbin/snmpd/snmpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.c,v 1.51 2024/04/08 13:18:54 tobhe Exp $ */ +/* $OpenBSD: snmpd.c,v 1.52 2024/04/12 14:17:42 bluhm Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter @@ -358,14 +358,10 @@ snmpd_backend(struct snmpd *env) } if (env->sc_flags & SNMPD_F_VERBOSE) argv[i++] = "-vv"; - if (env->sc_flags & SNMPD_F_DEBUG) { + if (env->sc_flags & SNMPD_F_DEBUG) argv[i++] = "-d"; - argv[i++] = "-x"; - argv[i++] = "3"; - } else { - argv[i++] = "-x"; - argv[i++] = "0"; - } + argv[i++] = "-x"; + argv[i++] = "3"; argv[i] = NULL; while ((file = readdir(dir)) != NULL) { if (file->d_name[0] == '.') @@ -377,10 +373,9 @@ snmpd_backend(struct snmpd *env) fatal("fork"); case 0: close(pair[1]); - if (dup2(pair[0], - env->sc_flags & SNMPD_F_DEBUG ? 3 : 0) == -1) + if (dup2(pair[0], 3) == -1) fatal("dup2"); - if (closefrom(env->sc_flags & SNMPD_F_DEBUG ? 4 : 1) == -1) + if (closefrom(4) == -1) fatal("closefrom"); (void)snprintf(execpath, sizeof(execpath), "%s/%s", SNMPD_BACKEND, file->d_name); -- 2.20.1