diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index a86d659cb040..13596450d2e1 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -710,9 +710,10 @@ show_var(int *oid, int nlen) warnx("malloc failed"); return (1); } + ctltype = (kind & CTLTYPE); len = j; i = sysctl(oid, nlen, val, &len, 0, 0); - if (i || !len) { + if (i != 0 || (len == 0 && ctltype != CTLTYPE_STRING)) { free(oval); return (1); } @@ -724,7 +725,6 @@ show_var(int *oid, int nlen) } val[len] = '\0'; p = val; - ctltype = (kind & CTLTYPE); sign = ctl_sign[ctltype]; intlen = ctl_size[ctltype];