changeset 1791:685b47d8faf7

fuzz: wrap kill()
author Matt Johnston <matt@ucc.asn.au>
date Fri, 29 Jan 2021 21:47:56 +0800
parents 42745af83b7d
children f90e681b8b8c
files fuzz-wrapfd.h fuzz.h fuzz/fuzz-wrapfd.c svr-chansession.c
diffstat 4 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/fuzz-wrapfd.h	Wed Feb 15 13:53:04 2017 +0100
+++ b/fuzz-wrapfd.h	Fri Jan 29 21:47:56 2021 +0800
@@ -1,6 +1,7 @@
 #ifndef FUZZ_WRAPFD_H
 #define FUZZ_WRAPFD_H
 
+#include "includes.h"
 #include "buffer.h"
 
 enum wrapfd_mode {
@@ -21,5 +22,6 @@
 int wrapfd_select(int nfds, fd_set *readfds, fd_set *writefds, 
     fd_set *exceptfds, struct timeval *timeout);
 int wrapfd_close(int fd);
+int fuzz_kill(pid_t pid, int sig);
 
 #endif // FUZZ_WRAPFD_H
--- a/fuzz.h	Wed Feb 15 13:53:04 2017 +0100
+++ b/fuzz.h	Fri Jan 29 21:47:56 2021 +0800
@@ -59,6 +59,7 @@
 #define write(fd, buf, count) wrapfd_write(fd, buf, count)
 #define read(fd, buf, count) wrapfd_read(fd, buf, count)
 #define close(fd) wrapfd_close(fd)
+#define kill(pid, sig) fuzz_kill(pid, sig)
 #endif // FUZZ_SKIP_WRAP
 
 struct dropbear_fuzz_options {
--- a/fuzz/fuzz-wrapfd.c	Wed Feb 15 13:53:04 2017 +0100
+++ b/fuzz/fuzz-wrapfd.c	Fri Jan 29 21:47:56 2021 +0800
@@ -258,3 +258,15 @@
 	return ret;
 }
 
+int fuzz_kill(pid_t pid, int sig) {
+	if (fuzz.fuzzing) {
+		TRACE(("fuzz_kill ignoring pid %d signal %d", (pid), sig))
+		if (sig >= 0) {
+			return 0;
+		} else {
+			errno = EINVAL;
+			return -1;
+		}
+	}
+	return kill(pid, sig);
+}
--- a/svr-chansession.c	Wed Feb 15 13:53:04 2017 +0100
+++ b/svr-chansession.c	Fri Jan 29 21:47:56 2021 +0800
@@ -423,12 +423,14 @@
 
 /* Send a signal to a session's process as requested by the client*/
 static int sessionsignal(const struct ChanSess *chansess) {
+	TRACE(("sessionsignal"))
 
 	int sig = 0;
 	char* signame = NULL;
 	int i;
 
 	if (chansess->pid == 0) {
+		TRACE(("sessionsignal: done no pid"))
 		/* haven't got a process pid yet */
 		return DROPBEAR_FAILURE;
 	}
@@ -446,12 +448,14 @@
 
 	m_free(signame);
 
+	TRACE(("sessionsignal: pid %d signal %d", (int)chansess->pid, sig))
 	if (sig == 0) {
 		/* failed */
 		return DROPBEAR_FAILURE;
 	}
 			
 	if (kill(chansess->pid, sig) < 0) {
+		TRACE(("sessionsignal: kill() errored"))
 		return DROPBEAR_FAILURE;
 	}