Description: Fix compilation warnings spanning various functions.
 Fixes a few compilation warnings such as quite serious cases
 where the return code of getcwd or system were silently ignored,
 leading to no logs in case of serious problems, or running in
 a restricted environment. A small minority I just pragma'ed
 away due to a high risk of changing legacy behavior
 when rewriting.
Author: Alexandru Mihail <alexandru.mihail2897@gmail.com>
Origin: maintainer
Forwarded: not-needed (sent by email; upstream has no public tracker)
Last-Update: 2026-02-26
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/htpasswd.c
+++ b/htpasswd.c
@@ -113,7 +113,11 @@
 
     if ( ! isatty( fileno( stdin ) ) )
 	{
-	(void) fgets( pass, sizeof(pass), stdin );
+	if (fgets(pass, sizeof(pass), stdin) == NULL)
+	{
+    	    fprintf(stderr, "Input error\n");
+    	    exit( 1 );
+	}
 	if ( pass[strlen(pass) - 1] == '\n' )
 	    pass[strlen(pass) - 1] = '\0';
 	pw = pass;
@@ -155,6 +159,7 @@
     char w[MAX_STRING_LEN];
     char command[MAX_STRING_LEN];
     int found;
+    int system_ret;
 
     tfd = -1;
     signal(SIGINT,(void (*)(int))interrupted);
@@ -213,7 +218,11 @@
     fclose(f);
     fclose(tfp);
     sprintf(command,"cp %s %s",temp_template,argv[1]);
-    system(command);
+    system_ret = system(command);
+    if (system_ret != 0)
+    {
+        printf("System call failed for cp\n");
+    }
     unlink(temp_template);
     exit(0);
 }
--- a/mini_httpd.c
+++ b/mini_httpd.c
@@ -676,7 +676,11 @@
 	}
 
     /* Get current directory. */
-    (void) getcwd( cwd, sizeof(cwd) - 1 );
+    if (getcwd(cwd, sizeof(cwd)) == NULL)
+    {
+	syslog( LOG_CRIT, "getcwd - %m" );
+    	exit( 1 );
+    }
     if ( cwd[strlen( cwd ) - 1] != '/' )
 	(void) strcat( cwd, "/" );
 
@@ -1923,8 +1927,9 @@
     closelog();
 
     /* Set priority. */
-    (void) nice( CGI_NICE );
-
+    errno = 0;
+    if (nice(CGI_NICE) == -1 && errno != 0)
+        syslog(LOG_WARNING, "nice(%d) failed: %m", CGI_NICE);
     /* Split the program into directory and binary, so we can chdir()
     ** to the program's own directory.  This isn't in the CGI 1.1
     ** spec, but it's what other HTTP servers do.
@@ -1936,7 +1941,12 @@
     else
 	{
 	*binary++ = '\0';
-	(void) chdir( directory );	/* ignore errors */
+	if (chdir(directory) < 0)
+	    {
+		/* ignore errors */
+    		;
+
+	    }
 	}
 
     /* Default behavior for SIGPIPE. */
@@ -2046,7 +2056,8 @@
 #endif /* USE_SSL */
 
     set_ndelay( conn_fd );
-    (void) read( conn_fd, buf, sizeof(buf) );
+    ssize_t __attribute__((unused)) nread;
+    nread = read(conn_fd, buf, sizeof(buf));
     clear_ndelay( conn_fd );
     }
 
@@ -2279,7 +2290,10 @@
     if ( pathinfo != (char*) 0 )
 	{
 	envp[envn++] = build_env( "PATH_INFO=/%s", pathinfo );
+	#pragma GCC diagnostic push
+        #pragma GCC diagnostic ignored "-Wformat-truncation"
 	(void) snprintf( buf, sizeof(buf), "%s%s", cwd, pathinfo );
+	#pragma GCC diagnostic pop
 	envp[envn++] = build_env( "PATH_TRANSLATED=%s", buf );
 	}
     if ( query[0] != '\0' )
@@ -2338,7 +2352,10 @@
 	    buf = (char*) e_realloc( (void*) buf, maxbuf );
 	    }
 	}
+    #pragma GCC diagnostic push
+    #pragma GCC diagnostic ignored "-Wformat-truncation"
     (void) snprintf( buf, maxbuf, fmt, arg );
+    #pragma GCC diagnostic pop
     cp = e_strdup( buf );
     return cp;
     }
@@ -3000,7 +3017,12 @@
 	zone = -zone;
 	}
     zone = ( zone / 60 ) * 100 + zone % 60;
-    (void) snprintf( date, sizeof(date), "%s %c%04d", date_nozone, sign, zone );
+    #pragma GCC diagnostic push
+    #pragma GCC diagnostic ignored "-Wformat-truncation"
+    (void) snprintf(date, sizeof(date),
+                "%s %c%04d",
+                date_nozone, sign, zone);
+    #pragma GCC diagnostic pop
     /* And write the log entry. */
     (void) fprintf( logfp,
 	"%.80s - %.80s [%s] \"%.80s %.200s %.80s\" %d %s \"%.200s\" \"%.200s\"\n",
