Module Name: src
Committed By: rillig
Date: Mon Aug 30 18:21:11 UTC 2021
Modified Files:
src/usr.sbin/inetd: Makefile inetd.c parse_v2.c
Log Message:
inetd: raise WARNS from 5 to 6
The necessary fixes include:
* explicit integer conversions, to get rid of mixed signedness
* function prototypes for parameterless functions
While here:
* add space after comma
* add space after 'if'
* place the '{' of a function definition on a separate line
* rename variables 'bits' and 'temp' to 'hi' and 'lo'
* in parse_quote, prefer expressions over assignments
* make hex_to_bits static
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/inetd/Makefile
cvs rdiff -u -r1.130 -r1.131 src/usr.sbin/inetd/inetd.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/inetd/parse_v2.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/inetd/Makefile
diff -u src/usr.sbin/inetd/Makefile:1.27 src/usr.sbin/inetd/Makefile:1.28
--- src/usr.sbin/inetd/Makefile:1.27 Sun Aug 29 11:43:48 2021
+++ src/usr.sbin/inetd/Makefile Mon Aug 30 18:21:11 2021
@@ -1,5 +1,5 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
-# $NetBSD: Makefile,v 1.27 2021/08/29 11:43:48 christos Exp $
+# $NetBSD: Makefile,v 1.28 2021/08/30 18:21:11 rillig Exp $
.include <bsd.own.mk>
@@ -9,6 +9,7 @@ PROG= inetd
SRCS= inetd.c parse_v2.c
MAN= inetd.8
MLINKS= inetd.8 inetd.conf.5
+WARNS= 6
# Enables debug printouts when in debug mode
CPPFLAGS+=-DDEBUG_ENABLE
Index: src/usr.sbin/inetd/inetd.c
diff -u src/usr.sbin/inetd/inetd.c:1.130 src/usr.sbin/inetd/inetd.c:1.131
--- src/usr.sbin/inetd/inetd.c:1.130 Mon Aug 30 17:32:23 2021
+++ src/usr.sbin/inetd/inetd.c Mon Aug 30 18:21:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: inetd.c,v 1.130 2021/08/30 17:32:23 rillig Exp $ */
+/* $NetBSD: inetd.c,v 1.131 2021/08/30 18:21:11 rillig Exp $ */
/*-
* Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
#if 0
static char sccsid[] = "@(#)inetd.c 8.4 (Berkeley) 4/13/94";
#else
-__RCSID("$NetBSD: inetd.c,v 1.130 2021/08/30 17:32:23 rillig Exp $");
+__RCSID("$NetBSD: inetd.c,v 1.131 2021/08/30 18:21:11 rillig Exp $");
#endif
#endif /* not lint */
@@ -801,7 +801,7 @@ config(void)
strlcpy(sep->se_ctrladdr_un.sun_path,
sep->se_service, n + 1);
sep->se_ctrladdr_un.sun_family = AF_LOCAL;
- sep->se_ctrladdr_size = (int)(n +
+ sep->se_ctrladdr_size = (socklen_t)(n +
sizeof(sep->se_ctrladdr_un) -
sizeof(sep->se_ctrladdr_un.sun_path));
if (!ISMUX(sep))
@@ -1825,12 +1825,12 @@ initring(void)
for (i = 0; i <= 128; ++i)
if (isprint(i))
- *endring++ = i;
+ *endring++ = (char)i;
}
/* ARGSUSED */
static void
-chargen_stream(int s,struct servtab *sep) /* Character generator */
+chargen_stream(int s, struct servtab *sep) /* Character generator */
{
size_t len;
char *rs, text[LINESIZ+2];
@@ -1845,7 +1845,7 @@ chargen_stream(int s,struct servtab *sep
text[LINESIZ] = '\r';
text[LINESIZ + 1] = '\n';
for (rs = ring;;) {
- if ((len = endring - rs) >= LINESIZ)
+ if ((len = (size_t)(endring - rs)) >= LINESIZ)
memmove(text, rs, LINESIZ);
else {
memmove(text, rs, len);
@@ -1882,7 +1882,7 @@ chargen_dg(int s, struct servtab *sep)
if (!port_good_dg(sa))
return;
- if ((len = endring - rs) >= LINESIZ)
+ if ((len = (size_t)(endring - rs)) >= LINESIZ)
memmove(text, rs, LINESIZ);
else {
memmove(text, rs, len);
@@ -1958,7 +1958,7 @@ daytime_stream(int s,struct servtab *sep
clk = time((time_t *) 0);
len = snprintf(buffer, sizeof buffer, "%.24s\r\n", ctime(&clk));
- (void) write(s, buffer, len);
+ (void) write(s, buffer, (size_t)len);
}
/* ARGSUSED */
@@ -1982,7 +1982,7 @@ daytime_dg(int s, struct servtab *sep)
if (!port_good_dg(sa))
return;
len = snprintf(buffer, sizeof buffer, "%.24s\r\n", ctime(&clk));
- (void) sendto(s, buffer, len, 0, sa, size);
+ (void) sendto(s, buffer, (size_t)len, 0, sa, size);
}
#ifdef DEBUG_ENABLE
@@ -2052,7 +2052,7 @@ get_line(int fd, char *buf, int len)
ssize_t n;
do {
- n = read(fd, buf, len-count);
+ n = read(fd, buf, (size_t)(len - count));
if (n == 0)
return (count);
if (n < 0)
@@ -2240,7 +2240,7 @@ allocchange(void)
}
static void
-config_root()
+config_root(void)
{
struct servtab *sep;
/* Uncheck services */
@@ -2438,7 +2438,8 @@ parse_accept_filter(char *arg, struct se
}
void
-parse_socktype(char* arg, struct servtab* sep) {
+parse_socktype(char* arg, struct servtab* sep)
+{
/* stream socket may have an accept filter, only check first chars */
if (strncmp(arg, "stream", sizeof("stream") - 1) == 0)
sep->se_socktype = SOCK_STREAM;
@@ -2455,7 +2456,8 @@ parse_socktype(char* arg, struct servtab
}
static struct servtab
-init_servtab() {
+init_servtab(void)
+{
/* This does not set every field to default. See enter() as well */
return (struct servtab) {
/*
@@ -2643,14 +2645,14 @@ check_no_reinclude(const char *glob_path
static char *
gen_file_pattern(const char *cur_config, const char *pattern)
{
- if(pattern[0] == '/') {
+ if (pattern[0] == '/') {
/* Absolute paths don't need any normalization */
return newstr(pattern);
}
/* pattern is relative */
/* Find the end of the file's directory */
- int i, last = 0;
+ size_t i, last = 0;
for (i = 0; cur_config[i] != '\0'; i++) {
if (cur_config[i] == '/') {
last = i;
@@ -2822,7 +2824,7 @@ rl_get_name(struct servtab *sep, int ctr
.msg_namelen = sizeof(struct sockaddr_storage),
/* scatter/gather and control info is null */
};
- int count;
+ ssize_t count;
/* Peek so service can still get the packet */
count = recvmsg(ctrl, &header, MSG_PEEK);
@@ -2879,7 +2881,7 @@ rl_drop_connection(struct servtab *sep,
struct msghdr header = {
/* All fields null, just consume one message */
};
- int count;
+ ssize_t count;
count = recvmsg(ctrl, &header, 0);
if (count == -1) {
@@ -2893,7 +2895,7 @@ rl_drop_connection(struct servtab *sep,
}
static time_t
-rl_time()
+rl_time(void)
{
struct timespec time;
if(clock_gettime(CLOCK_MONOTONIC, &time) == -1) {
Index: src/usr.sbin/inetd/parse_v2.c
diff -u src/usr.sbin/inetd/parse_v2.c:1.3 src/usr.sbin/inetd/parse_v2.c:1.4
--- src/usr.sbin/inetd/parse_v2.c:1.3 Mon Aug 30 17:32:23 2021
+++ src/usr.sbin/inetd/parse_v2.c Mon Aug 30 18:21:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: parse_v2.c,v 1.3 2021/08/30 17:32:23 rillig Exp $ */
+/* $NetBSD: parse_v2.c,v 1.4 2021/08/30 18:21:11 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: parse_v2.c,v 1.3 2021/08/30 17:32:23 rillig Exp $");
+__RCSID("$NetBSD: parse_v2.c,v 1.4 2021/08/30 18:21:11 rillig Exp $");
#include <ctype.h>
#include <errno.h>
@@ -95,7 +95,7 @@ static int size_to_bytes(char *);
static bool infer_protocol_ip_version(struct servtab *);
static bool setup_internal(struct servtab *);
static void try_infer_socktype(struct servtab *);
-int hex_to_bits(char);
+static int hex_to_bits(char);
#ifdef IPSEC
static void setup_ipsec(struct servtab *);
#endif
@@ -337,7 +337,7 @@ skip_whitespace(char **cpp)
{
char *cp = *cpp;
- int line_start = line_number;
+ size_t line_start = line_number;
for (;;) {
while (isblank((unsigned char)*cp))
@@ -348,7 +348,7 @@ skip_whitespace(char **cpp)
/* Should never expect EOF when skipping whitespace */
if (cp == NULL) {
- ERR("Early end of file after line %d",
+ ERR("Early end of file after line %zu",
line_start);
return false;
}
@@ -405,16 +405,14 @@ parse_quotes(char **cpp)
cp++;
switch (*cp) {
case 'x': {
- int temp, bits;
- if (((bits = hex_to_bits(*(cp + 1))) == -1)
- || ((temp = hex_to_bits(*(cp + 2))) == -1)) {
+ int hi, lo;
+ if ((hi = hex_to_bits(cp[1])) == -1
+ || (lo = hex_to_bits(cp[2])) == -1) {
ERR("Invalid hexcode sequence '%.4s'",
start);
return false;
}
- bits <<= 4;
- bits |= temp;
- *start = bits;
+ *start = (char)((hi << 4) | lo);
strmove(cp, 3);
continue;
}
@@ -459,7 +457,7 @@ parse_quotes(char **cpp)
return true;
}
-int
+static int
hex_to_bits(char in)
{
switch(in) {
@@ -511,7 +509,7 @@ next_value(vlist list)
* Found the start of a potential value. Advance one character
* past the end of the value.
*/
- char * start = cp;
+ char *start = cp;
while (!isblank((unsigned char)*cp) && *cp != '#' &&
*cp != ',' && *cp != ';' && *cp != '\0' ) {
if (*cp == '"' || *cp == '\'') {