NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/56367: bozohttpd.c 80-wide



>Number:         56367
>Category:       bin
>Synopsis:       bozohttpd.c 80-wide
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 17 19:55:01 +0000 2021
>Originator:     parrott
>Release:        HEAD as of a few days ago, unless i'm mistaken
>Organization:
individual
>Environment:
9.2, HEAD src
>Description:
mostly just 80-wide

+ i think there's an unnecessary USE_ARG
+ i took a stab at an if block
>How-To-Repeat:

>Fix:
Index: bozohttpd.c
===================================================================
RCS file: /cvsroot/src/libexec/httpd/bozohttpd.c,v
retrieving revision 1.132
diff -u -p -r1.132 bozohttpd.c
--- bozohttpd.c	5 May 2021 07:41:48 -0000	1.132
+++ bozohttpd.c	17 Aug 2021 19:47:47 -0000
@@ -148,8 +148,8 @@
 #include "bozohttpd.h"
 
 #ifndef SSL_TIMEOUT
-#define	SSL_TIMEOUT		"30"	/* wait for 30 seconds for ssl handshake  */
-#endif
+#define	SSL_TIMEOUT		"30"	/* wait for 30 seconds for ssl */
+#endif					/* handshake */
 #ifndef INITIAL_TIMEOUT
 #define	INITIAL_TIMEOUT		"30"	/* wait for 30 seconds initially */
 #endif
@@ -291,7 +291,6 @@ parse_request(bozohttpd_t *httpd, char *
 	ssize_t	len;
 	char	*val;
 
-	USE_ARG(httpd);
 	debug((httpd, DEBUG_EXPLODING, "parse in: %s", in));
 	*method = *file = *query = *proto = NULL;
 
@@ -670,23 +669,19 @@ bozo_read_request(bozohttpd_t *httpd)
 	 * Override the bound port from the request value, so it works even
 	 * if passed through a proxy that doesn't rewrite the port.
 	 */
-	if (httpd->bindport) {
+	if (httpd->bindport)
 		if (strcmp(httpd->bindport, BOZO_HTTP_PORT) != 0)
 			port = httpd->bindport;
 		else
 			port = NULL;
-	} else {
-		if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0)
-			port = NULL;
-		else {
-			if (getnameinfo((struct sockaddr *)(void *)&ss, slen,
-					NULL, 0, bufport, sizeof bufport,
-					NI_NUMERICSERV) == 0)
-				port = bufport;
-			else
-				port = NULL;
-		}
-	}
+	else if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0)
+		port = NULL;
+	else if (getnameinfo((struct sockaddr *)(void *)&ss, slen, NULL, 0,
+	    bufport, sizeof bufport, NI_NUMERICSERV) == 0)
+		port = bufport;
+	else
+		port = NULL;
+
 	if (port != NULL)
 		request->hr_serverport = bozostrdup(httpd, request, port);
 
@@ -713,11 +708,13 @@ bozo_read_request(bozohttpd_t *httpd)
 		return NULL;
 
 	alarm(httpd->initial_timeout);
-	while ((str = bozodgetln(httpd, STDIN_FILENO, &len, bozo_read)) != NULL) {
+	while ((str = bozodgetln(httpd, STDIN_FILENO, &len, bozo_read)) != NULL)
+	    {
 		alarm(0);
 
 		if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
-			bozo_http_error(httpd, 500, NULL, "clock_gettime failed");
+			bozo_http_error(httpd, 500, NULL,
+			    "clock_gettime failed");
 			goto cleanup;
 		}
 		/*
@@ -744,7 +741,8 @@ bozo_read_request(bozohttpd_t *httpd)
 
 		if (line == 1) {
 			if (len < 1) {
-				bozo_http_error(httpd, 404, NULL, "null method");
+				bozo_http_error(httpd, 404, NULL,
+				    "null method");
 				goto cleanup;
 			}
 			bozowarn(httpd,
@@ -754,11 +752,13 @@ bozo_read_request(bozohttpd_t *httpd)
 				  port ? port : "<stdin>");
 
 			/* we allocate return space in file and query only */
-			parse_request(httpd, str, &method, &file, &query, &proto);
+			parse_request(httpd, str, &method, &file, &query,
+			    &proto);
 			request->hr_file_free = request->hr_file = file;
 			request->hr_query = query;
 			if (method == NULL) {
-				bozo_http_error(httpd, 404, NULL, "null method");
+				bozo_http_error(httpd, 404, NULL,
+				    "null method");
 				goto cleanup;
 			}
 			if (file == NULL) {
@@ -770,7 +770,6 @@ bozo_read_request(bozohttpd_t *httpd)
 			 * note that we parse the proto first, so that we
 			 * can more properly parse the method and the url.
 			 */
-
 			if (process_proto(request, proto) ||
 			    process_method(request, method)) {
 				goto cleanup;
@@ -794,7 +793,8 @@ bozo_read_request(bozohttpd_t *httpd)
 			    "bozostrnsep: str `%s' val `%s'",
 			    str ? str : "<null>", val ? val : "<null>"));
 			if (val == NULL || len == -1) {
-				bozo_http_error(httpd, 404, request, "no header");
+				bozo_http_error(httpd, 404, request,
+				    "no header");
 				goto cleanup;
 			}
 			if (str == NULL) {
@@ -817,7 +817,8 @@ bozo_read_request(bozohttpd_t *httpd)
 
 			if (strcasecmp(hdr->h_header, "content-type") == 0)
 				request->hr_content_type = hdr->h_value;
-			else if (strcasecmp(hdr->h_header, "content-length") == 0)
+			else if (strcasecmp(hdr->h_header, "content-length") ==
+			    0)
 				request->hr_content_length = hdr->h_value;
 			else if (strcasecmp(hdr->h_header, "host") == 0) {
 				if (request->hr_host) {
@@ -897,8 +898,9 @@ next_header:
 					if (*dash != '\0') {
 						request->hr_last_byte_pos =
 						    strtoll(dash, NULL, 10);
-						if (request->hr_last_byte_pos < 0)
-							request->hr_last_byte_pos = -1;
+						if (request->hr_last_byte_pos <
+						    0)
+						request->hr_last_byte_pos = -1;
 					}
 				}
 			}
@@ -1129,7 +1131,8 @@ handle_redirect(bozo_httpreq_t *request,
 		hostname = "";
 		portbuf[0] = '\0';
 	} else {
-		const char *defport = httpd->sslinfo ? BOZO_HTTPS_PORT : BOZO_HTTP_PORT;
+		const char *defport = httpd->sslinfo ? BOZO_HTTPS_PORT :
+		    BOZO_HTTP_PORT;
 
 		if (request->hr_serverport &&
 		    strcmp(request->hr_serverport, defport) != 0)
@@ -1162,7 +1165,8 @@ handle_redirect(bozo_httpreq_t *request,
 	bozo_printf(httpd, "\r\n");
 	if (request->hr_method == HTTP_HEAD)
 		goto head;
-	bozo_printf(httpd, "<html><head><title>Document Moved</title></head>\n");
+	bozo_printf(httpd,
+	     "<html><head><title>Document Moved</title></head>\n");
 	bozo_printf(httpd, "<body><h1>Document Moved</h1>\n");
 	bozo_printf(httpd, "This document had moved <a href=\"%s\">here</a>\n",
 	  finalurl);
@@ -1417,9 +1421,11 @@ check_virtual(bozo_httpreq_t *request)
 			 	   d->d_name));
 				if (strcmp(d->d_name, request->hr_host) == 0) {
 					/* found it, punch it */
-					debug((httpd, DEBUG_OBESE, "found it punch it"));
+					debug((httpd, DEBUG_OBESE, "found it "
+					    "punch it"));
 					request->hr_virthostname =
-					    bozostrdup(httpd, request, d->d_name);
+					    bozostrdup(httpd, request,
+					    d->d_name);
 					bozoasprintf(httpd, &s, "%s/%s",
 					    httpd->virtbase,
 					    request->hr_virthostname);
@@ -1537,8 +1543,10 @@ check_bzredirect(bozo_httpreq_t *request
 
 	/* now we have the link pointer, redirect to the real place */
 	if (!absolute && redirpath[0] != '/') {
-		if ((size_t)snprintf(finalredir = redir, sizeof(redir), "%s%s/%s",
-		  (strlen(dir) > 0 ? "/" : ""), dir, redirpath) >= sizeof(redir)) {
+		if ((size_t)snprintf(finalredir = redir, sizeof(redir),
+		    "%s%s/%s",
+		    (strlen(dir) > 0 ? "/" : ""), dir, redirpath) >= 
+		    sizeof(redir)) {
 			bozo_http_error(httpd, 404, request,
 					"redirect path too long");
 			return -1;
@@ -1950,7 +1958,8 @@ bozo_process_request(bozo_httpreq_t *req
 
 /* make sure we're not trying to access special files */
 int
-bozo_check_special_files(bozo_httpreq_t *request, const char *name, bool doerror)
+bozo_check_special_files(bozo_httpreq_t *request, const char *name,
+    bool doerror)
 {
 	bozohttpd_t *httpd = request->hr_httpd;
 	size_t i;



Home | Main Index | Thread Index | Old Index