vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Petr Lautrbach 44f0ac
diff --git a/auth-pam.c b/auth-pam.c
Jakub Jelen 580f98
index cd1a775..2fff267 100644
Petr Lautrbach 44f0ac
--- a/auth-pam.c
Petr Lautrbach 44f0ac
+++ b/auth-pam.c
Petr Lautrbach 44f0ac
@@ -216,7 +216,12 @@ pthread_join(sp_pthread_t thread, void **value)
Jan F. Chadima 3b545b
 	if (sshpam_thread_status != -1)
Jan F. Chadima 3b545b
 		return (sshpam_thread_status);
Jan F. Chadima 3b545b
 	signal(SIGCHLD, sshpam_oldsig);
Jan F. Chadima 3b545b
-	waitpid(thread, &status, 0);
Jakub Jelen 580f98
+	while (waitpid(thread, &status, 0) < 0) {
Jakub Jelen 580f98
+		if (errno == EINTR)
Jan F. Chadima c870e6
+			continue;
Jakub Jelen 580f98
+		fatal("%s: waitpid: %s", __func__,
Jakub Jelen 580f98
+				strerror(errno));
Jan F. Chadima c870e6
+	}
Jan F. Chadima 3b545b
 	return (status);
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 #endif
Petr Lautrbach 44f0ac
diff --git a/channels.c b/channels.c
Jakub Jelen 580f98
index 51a221d..0ef1d90 100644
Petr Lautrbach 44f0ac
--- a/channels.c
Petr Lautrbach 44f0ac
+++ b/channels.c
Jakub Jelen 580f98
@@ -239,11 +239,11 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd,
Jan F. Chadima 3b545b
 	channel_max_fd = MAX(channel_max_fd, wfd);
Jan F. Chadima 3b545b
 	channel_max_fd = MAX(channel_max_fd, efd);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
-	if (rfd != -1)
Jan F. Chadima 3b545b
+	if (rfd >= 0)
Jan F. Chadima 3b545b
 		fcntl(rfd, F_SETFD, FD_CLOEXEC);
Jan F. Chadima 3b545b
-	if (wfd != -1 && wfd != rfd)
Jan F. Chadima 3b545b
+	if (wfd >= 0 && wfd != rfd)
Jan F. Chadima 3b545b
 		fcntl(wfd, F_SETFD, FD_CLOEXEC);
Jan F. Chadima 3b545b
-	if (efd != -1 && efd != rfd && efd != wfd)
Jan F. Chadima 3b545b
+	if (efd >= 0 && efd != rfd && efd != wfd)
Jan F. Chadima 3b545b
 		fcntl(efd, F_SETFD, FD_CLOEXEC);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	c->rfd = rfd;
Jakub Jelen 580f98
@@ -261,11 +261,11 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd,
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	/* enable nonblocking mode */
Jan F. Chadima 3b545b
 	if (nonblock) {
Jan F. Chadima 3b545b
-		if (rfd != -1)
Jan F. Chadima 3b545b
+		if (rfd >= 0)
Jan F. Chadima 3b545b
 			set_nonblock(rfd);
Jan F. Chadima 3b545b
-		if (wfd != -1)
Jan F. Chadima 3b545b
+		if (wfd >= 0)
Jan F. Chadima 3b545b
 			set_nonblock(wfd);
Jan F. Chadima 3b545b
-		if (efd != -1)
Jan F. Chadima 3b545b
+		if (efd >= 0)
Jan F. Chadima 3b545b
 			set_nonblock(efd);
Jan F. Chadima 3b545b
 	}
Jan F. Chadima 3b545b
 }
Jakub Jelen 580f98
@@ -3959,13 +3959,13 @@ connect_local_xsocket_path(const char *pathname, int len)
Jakub Jelen 580f98
 	int sock;
Jakub Jelen 580f98
 	struct sockaddr_un addr;
Jakub Jelen 580f98
 
Jakub Jelen 580f98
+	if (len <= 0)
Jakub Jelen 580f98
+		return -1;
Jakub Jelen 580f98
 	sock = socket(AF_UNIX, SOCK_STREAM, 0);
Jakub Jelen 580f98
 	if (sock < 0)
Jakub Jelen 580f98
 		error("socket: %.100s", strerror(errno));
Jakub Jelen 580f98
 	memset(&addr, 0, sizeof(addr));
Jakub Jelen 580f98
 	addr.sun_family = AF_UNIX;
Jakub Jelen 580f98
-	if (len <= 0)
Jakub Jelen 580f98
-		return -1;
Jakub Jelen 580f98
 	if (len > sizeof addr.sun_path)
Jakub Jelen 580f98
 		len = sizeof addr.sun_path;
Jakub Jelen 580f98
 	memcpy(addr.sun_path, pathname, len);
Petr Lautrbach 44f0ac
diff --git a/clientloop.c b/clientloop.c
Jakub Jelen 580f98
index 20ce0b5..65cb26a 100644
Petr Lautrbach 44f0ac
--- a/clientloop.c
Petr Lautrbach 44f0ac
+++ b/clientloop.c
Jakub Jelen 580f98
@@ -2090,15 +2090,16 @@ client_input_global_request(int type, u_int32_t seq, void *ctxt)
Jakub Jelen 580f98
 {
Petr Lautrbach 8a29de
 	char *rtype;
Petr Lautrbach 8a29de
 	int want_reply;
Jakub Jelen 580f98
-	int success = 0;
Jakub Jelen 580f98
+/*	int success = 0;
Jakub Jelen 580f98
+ success is still 0 the packet is allways SSH2_MSG_REQUEST_FAILURE, isn't it? */
Petr Lautrbach 8a29de
 
Petr Lautrbach 8a29de
 	rtype = packet_get_string(NULL);
Petr Lautrbach 8a29de
 	want_reply = packet_get_char();
Petr Lautrbach 8a29de
 	debug("client_input_global_request: rtype %s want_reply %d",
Petr Lautrbach 8a29de
 	    rtype, want_reply);
Petr Lautrbach 8a29de
 	if (want_reply) {
Petr Lautrbach 8a29de
-		packet_start(success ?
Petr Lautrbach 8a29de
-		    SSH2_MSG_REQUEST_SUCCESS : SSH2_MSG_REQUEST_FAILURE);
Petr Lautrbach 8a29de
+		packet_start(/*success ?
Petr Lautrbach 8a29de
+		    SSH2_MSG_REQUEST_SUCCESS :*/ SSH2_MSG_REQUEST_FAILURE);
Petr Lautrbach 8a29de
 		packet_send();
Petr Lautrbach 8a29de
 		packet_write_wait();
Petr Lautrbach 8a29de
 	}
Jakub Jelen 580f98
diff --git a/entropy.c b/entropy.c
Jakub Jelen 580f98
index 06b0095..a4097da 100644
Jakub Jelen 580f98
--- a/entropy.c
Jakub Jelen 580f98
+++ b/entropy.c
Jakub Jelen 580f98
@@ -44,6 +44,7 @@
Jakub Jelen 580f98
 #include <openssl/err.h>
Jakub Jelen 580f98
 
Jakub Jelen 580f98
 #include "openbsd-compat/openssl-compat.h"
Jakub Jelen 580f98
+#include "openbsd-compat/port-linux.h"
Jakub Jelen 580f98
 
Jakub Jelen 580f98
 #include "ssh.h"
Jakub Jelen 580f98
 #include "misc.h"
Petr Lautrbach 44f0ac
diff --git a/monitor.c b/monitor.c
Jakub Jelen 580f98
index 07fa655..b8e6e06 100644
Petr Lautrbach 44f0ac
--- a/monitor.c
Petr Lautrbach 44f0ac
+++ b/monitor.c
Jakub Jelen 580f98
@@ -488,7 +488,7 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
Petr Lautrbach 8a29de
 	mm_get_keystate(pmonitor);
Jan F. Chadima cff1d0
 
Jan F. Chadima cff1d0
 	/* Drain any buffered messages from the child */
Jan F. Chadima cff1d0
-	while (pmonitor->m_log_recvfd != -1 && monitor_read_log(pmonitor) == 0)
Jan F. Chadima cff1d0
+	while (pmonitor->m_log_recvfd >= 0 && monitor_read_log(pmonitor) == 0)
Jan F. Chadima cff1d0
 		;
Jan F. Chadima cff1d0
 
Petr Lautrbach 8a29de
 	close(pmonitor->m_sendfd);
Jakub Jelen 580f98
@@ -1276,6 +1276,10 @@ mm_answer_keyallowed(int sock, Buffer *m)
Jan F. Chadima ea97ff
 			break;
Jan F. Chadima ea97ff
 		}
Jan F. Chadima ea97ff
 	}
Jan F. Chadima ea97ff
+
Jan F. Chadima ea97ff
+	debug3("%s: key %p is %s",
Jan F. Chadima ea97ff
+	    __func__, key, allowed ? "allowed" : "not allowed");
Jan F. Chadima ea97ff
+
Jan F. Chadima ea97ff
 	if (key != NULL)
Jan F. Chadima ea97ff
 		key_free(key);
Jan F. Chadima ea97ff
 
Jakub Jelen 580f98
@@ -1297,9 +1301,6 @@ mm_answer_keyallowed(int sock, Buffer *m)
Petr Lautrbach 84822b
 		free(chost);
Jan F. Chadima ea97ff
 	}
Jan F. Chadima ea97ff
 
Jan F. Chadima ea97ff
-	debug3("%s: key %p is %s",
Jan F. Chadima ea97ff
-	    __func__, key, allowed ? "allowed" : "not allowed");
Jan F. Chadima ea97ff
-
Jan F. Chadima ea97ff
 	buffer_clear(m);
Jan F. Chadima ea97ff
 	buffer_put_int(m, allowed);
Jan F. Chadima ea97ff
 	buffer_put_int(m, forced_command != NULL);
Petr Lautrbach 44f0ac
diff --git a/monitor_wrap.c b/monitor_wrap.c
Jakub Jelen 580f98
index ba4ecd7..b3e4ca1 100644
Petr Lautrbach 44f0ac
--- a/monitor_wrap.c
Petr Lautrbach 44f0ac
+++ b/monitor_wrap.c
Jakub Jelen 580f98
@@ -749,10 +749,10 @@ mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
Jan F. Chadima cff1d0
 	if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
Jan F. Chadima cff1d0
 	    (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
Jan F. Chadima cff1d0
 		error("%s: cannot allocate fds for pty", __func__);
Jan F. Chadima cff1d0
-		if (tmp1 > 0)
Jan F. Chadima cff1d0
+		if (tmp1 >= 0)
Jan F. Chadima cff1d0
 			close(tmp1);
Jan F. Chadima cff1d0
-		if (tmp2 > 0)
Jan F. Chadima cff1d0
-			close(tmp2);
Jan F. Chadima cff1d0
+		/*DEAD CODE if (tmp2 >= 0)
Jan F. Chadima cff1d0
+			close(tmp2);*/
Jan F. Chadima cff1d0
 		return 0;
Jan F. Chadima cff1d0
 	}
Jan F. Chadima cff1d0
 	close(tmp1);
Petr Lautrbach 44f0ac
diff --git a/openbsd-compat/bindresvport.c b/openbsd-compat/bindresvport.c
Petr Lautrbach 44f0ac
index c89f214..80115c2 100644
Petr Lautrbach 44f0ac
--- a/openbsd-compat/bindresvport.c
Petr Lautrbach 44f0ac
+++ b/openbsd-compat/bindresvport.c
Petr Lautrbach 44f0ac
@@ -58,7 +58,7 @@ bindresvport_sa(int sd, struct sockaddr *sa)
Jan F. Chadima ea97ff
 	struct sockaddr_in6 *in6;
Jan F. Chadima ea97ff
 	u_int16_t *portp;
Jan F. Chadima ea97ff
 	u_int16_t port;
Jan F. Chadima ea97ff
-	socklen_t salen;
Jan F. Chadima ea97ff
+	socklen_t salen = sizeof(struct sockaddr_storage);
Jan F. Chadima ea97ff
 	int i;
Jan F. Chadima ea97ff
 
Jan F. Chadima ea97ff
 	if (sa == NULL) {
Jakub Jelen 580f98
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
Jakub Jelen 580f98
index 8b7cda2..e2ca8a1 100644
Jakub Jelen 580f98
--- a/openbsd-compat/port-linux.h
Jakub Jelen 580f98
+++ b/openbsd-compat/port-linux.h
Jakub Jelen 580f98
@@ -37,4 +37,6 @@ void oom_adjust_restore(void);
Jakub Jelen 580f98
 void oom_adjust_setup(void);
Jakub Jelen 580f98
 #endif
Jakub Jelen 580f98
 
Jakub Jelen 580f98
+void linux_seed(void);
Jakub Jelen 580f98
+
Jakub Jelen 580f98
 #endif /* ! _PORT_LINUX_H */
Petr Lautrbach 44f0ac
diff --git a/packet.c b/packet.c
Jakub Jelen 580f98
index 8ec353e..dbc2c33 100644
Petr Lautrbach 44f0ac
--- a/packet.c
Petr Lautrbach 44f0ac
+++ b/packet.c
Jakub Jelen 580f98
@@ -1246,6 +1246,7 @@ packet_read_poll1(void)
Jan F. Chadima 3b545b
 		case DEATTACK_DETECTED:
Jan F. Chadima 3b545b
 			packet_disconnect("crc32 compensation attack: "
Jan F. Chadima 3b545b
 			    "network attack detected");
Jan F. Chadima 3b545b
+			break;
Jan F. Chadima 3b545b
 		case DEATTACK_DOS_DETECTED:
Jan F. Chadima 3b545b
 			packet_disconnect("deattack denial of "
Jan F. Chadima 3b545b
 			    "service detected");
Jakub Jelen 580f98
diff --git a/pam_ssh_agent_auth-0.9.3/pam_user_key_allowed2.c b/pam_ssh_agent_auth-0.9.3/pam_user_key_allowed2.c
Jakub Jelen 580f98
index 8ba6d87..a7808c7 100644
Jakub Jelen 580f98
--- a/pam_ssh_agent_auth-0.9.3/pam_user_key_allowed2.c
Jakub Jelen 580f98
+++ b/pam_ssh_agent_auth-0.9.3/pam_user_key_allowed2.c
Jakub Jelen 580f98
@@ -87,7 +87,7 @@ pam_user_key_allowed2(struct passwd *pw, Key *key, char *file)
Jakub Jelen 580f98
 	found = key_new(key->type);
Jakub Jelen 580f98
 
Jakub Jelen 580f98
 	while (read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) {
Jakub Jelen 580f98
-		char *cp, *key_options = NULL;
Jakub Jelen 580f98
+		char *cp = NULL;
Jakub Jelen 580f98
 
Jakub Jelen 580f98
 		/* Skip leading whitespace, empty and comment lines. */
Jakub Jelen 580f98
 		for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
Jakub Jelen 580f98
@@ -99,7 +99,6 @@ pam_user_key_allowed2(struct passwd *pw, Key *key, char *file)
Jakub Jelen 580f98
 			/* no key?  check if there are options for this key */
Jakub Jelen 580f98
 			int quoted = 0;
Jakub Jelen 580f98
 			verbose("user_key_allowed: check options: '%s'", cp);
Jakub Jelen 580f98
-			key_options = cp;
Jakub Jelen 580f98
 			for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
Jakub Jelen 580f98
 				if (*cp == '\\' && cp[1] == '"')
Jakub Jelen 580f98
 					cp++;	/* Skip both */
Jakub Jelen 580f98
diff --git a/pam_ssh_agent_auth-0.9.3/userauth_pubkey_from_id.c b/pam_ssh_agent_auth-0.9.3/userauth_pubkey_from_id.c
Jakub Jelen 580f98
index e14eb27..323817a 100644
Jakub Jelen 580f98
--- a/pam_ssh_agent_auth-0.9.3/userauth_pubkey_from_id.c
Jakub Jelen 580f98
+++ b/pam_ssh_agent_auth-0.9.3/userauth_pubkey_from_id.c
Jakub Jelen 580f98
@@ -89,8 +89,7 @@ userauth_pubkey_from_id(Identity * id)
Jakub Jelen 580f98
         authenticated = 1;
Jakub Jelen 580f98
 
Jakub Jelen 580f98
   user_auth_clean_exit:
Jakub Jelen 580f98
-    if(&b != NULL)
Jakub Jelen 580f98
-        buffer_free(&b);
Jakub Jelen 580f98
+    buffer_free(&b);
Jakub Jelen 580f98
     if(sig != NULL)
Jakub Jelen 580f98
         free(sig);
Jakub Jelen 580f98
     if(pkblob != NULL)
Petr Lautrbach 44f0ac
diff --git a/progressmeter.c b/progressmeter.c
Petr Lautrbach 44f0ac
index bbbc706..ae6d1aa 100644
Petr Lautrbach 44f0ac
--- a/progressmeter.c
Petr Lautrbach 44f0ac
+++ b/progressmeter.c
Jan F. Chadima 3b545b
@@ -65,7 +65,7 @@ static void update_progress_meter(int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 static time_t start;		/* start progress */
Jan F. Chadima 3b545b
 static time_t last_update;	/* last progress update */
Jan F. Chadima 3b545b
-static char *file;		/* name of the file being transferred */
Jan F. Chadima 3b545b
+static const char *file;	/* name of the file being transferred */
Petr Lautrbach 44f0ac
 static off_t start_pos;		/* initial position of transfer */
Jan F. Chadima 3b545b
 static off_t end_pos;		/* ending position of transfer */
Jan F. Chadima 3b545b
 static off_t cur_pos;		/* transfer position as of last refresh */
Petr Lautrbach 44f0ac
@@ -248,7 +248,7 @@ update_progress_meter(int ignore)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 void
Jan F. Chadima 3b545b
-start_progress_meter(char *f, off_t filesize, off_t *ctr)
Jan F. Chadima 3b545b
+start_progress_meter(const char *f, off_t filesize, off_t *ctr)
Jan F. Chadima 3b545b
 {
Petr Lautrbach 84822b
 	start = last_update = monotime();
Jan F. Chadima 3b545b
 	file = f;
Petr Lautrbach 44f0ac
diff --git a/progressmeter.h b/progressmeter.h
Petr Lautrbach 44f0ac
index 10bab99..e9ca8f0 100644
Petr Lautrbach 44f0ac
--- a/progressmeter.h
Petr Lautrbach 44f0ac
+++ b/progressmeter.h
Jan F. Chadima 3b545b
@@ -23,5 +23,5 @@
Jan F. Chadima 3b545b
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jan F. Chadima 3b545b
  */
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
-void	start_progress_meter(char *, off_t, off_t *);
Jan F. Chadima 3b545b
+void	start_progress_meter(const char *, off_t, off_t *);
Jan F. Chadima 3b545b
 void	stop_progress_meter(void);
Petr Lautrbach 44f0ac
diff --git a/scp.c b/scp.c
Jakub Jelen 580f98
index cbd904d..e4e9fa1 100644
Petr Lautrbach 44f0ac
--- a/scp.c
Petr Lautrbach 44f0ac
+++ b/scp.c
Jan F. Chadima 3b545b
@@ -155,7 +155,7 @@ killchild(int signo)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	if (do_cmd_pid > 1) {
Jan F. Chadima 3b545b
 		kill(do_cmd_pid, signo ? signo : SIGTERM);
Jan F. Chadima 3b545b
-		waitpid(do_cmd_pid, NULL, 0);
Jan F. Chadima 3b545b
+		(void) waitpid(do_cmd_pid, NULL, 0);
Jan F. Chadima 3b545b
 	}
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	if (signo)
Petr Lautrbach 44f0ac
diff --git a/servconf.c b/servconf.c
Jakub Jelen 580f98
index 87a311b..895cdca 100644
Petr Lautrbach 44f0ac
--- a/servconf.c
Petr Lautrbach 44f0ac
+++ b/servconf.c
Jakub Jelen 580f98
@@ -1418,7 +1418,7 @@ process_server_config_line(ServerOptions *options, char *line,
Jan F. Chadima ea97ff
 			fatal("%s line %d: Missing subsystem name.",
Jan F. Chadima ea97ff
 			    filename, linenum);
Jan F. Chadima ea97ff
 		if (!*activep) {
Jan F. Chadima ea97ff
-			arg = strdelim(&cp;;
Jan F. Chadima ea97ff
+			/*arg =*/ (void) strdelim(&cp;;
Jan F. Chadima ea97ff
 			break;
Jan F. Chadima ea97ff
 		}
Jan F. Chadima ea97ff
 		for (i = 0; i < options->num_subsystems; i++)
Jakub Jelen 580f98
@@ -1509,8 +1509,9 @@ process_server_config_line(ServerOptions *options, char *line,
Jan F. Chadima cff1d0
 		if (*activep && *charptr == NULL) {
Jan F. Chadima cff1d0
 			*charptr = tilde_expand_filename(arg, getuid());
Jan F. Chadima cff1d0
 			/* increase optional counter */
Jan F. Chadima cff1d0
-			if (intptr != NULL)
Jan F. Chadima cff1d0
-				*intptr = *intptr + 1;
Jan F. Chadima cff1d0
+			/* DEAD CODE intptr is still NULL ;)
Jan F. Chadima cff1d0
+  			 if (intptr != NULL)
Jan F. Chadima cff1d0
+				*intptr = *intptr + 1; */
Jan F. Chadima cff1d0
 		}
Jan F. Chadima cff1d0
 		break;
Jan F. Chadima cff1d0
 
Petr Lautrbach 44f0ac
diff --git a/serverloop.c b/serverloop.c
Jakub Jelen 580f98
index e92f9e2..3cad041 100644
Petr Lautrbach 44f0ac
--- a/serverloop.c
Petr Lautrbach 44f0ac
+++ b/serverloop.c
Jan F. Chadima 3b545b
@@ -147,13 +147,13 @@ notify_setup(void)
Jan F. Chadima 3b545b
 static void
Jan F. Chadima 3b545b
 notify_parent(void)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
-	if (notify_pipe[1] != -1)
Jan F. Chadima 3b545b
+	if (notify_pipe[1] >= 0)
Petr Lautrbach 84822b
 		(void)write(notify_pipe[1], "", 1);
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 static void
Jan F. Chadima 3b545b
 notify_prepare(fd_set *readset)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
-	if (notify_pipe[0] != -1)
Jan F. Chadima 3b545b
+	if (notify_pipe[0] >= 0)
Jan F. Chadima 3b545b
 		FD_SET(notify_pipe[0], readset);
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 static void
Jan F. Chadima 3b545b
@@ -161,8 +161,8 @@ notify_done(fd_set *readset)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	char c;
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
-	if (notify_pipe[0] != -1 && FD_ISSET(notify_pipe[0], readset))
Jan F. Chadima 3b545b
-		while (read(notify_pipe[0], &c, 1) != -1)
Jan F. Chadima 3b545b
+	if (notify_pipe[0] >= 0 && FD_ISSET(notify_pipe[0], readset))
Jan F. Chadima 3b545b
+		while (read(notify_pipe[0], &c, 1) >= 0)
Jan F. Chadima 3b545b
 			debug2("notify_done: reading");
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -337,7 +337,7 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
Jan F. Chadima 3b545b
 		 * If we have buffered data, try to write some of that data
Jan F. Chadima 3b545b
 		 * to the program.
Jan F. Chadima 3b545b
 		 */
Jan F. Chadima 3b545b
-		if (fdin != -1 && buffer_len(&stdin_buffer) > 0)
Jan F. Chadima 3b545b
+		if (fdin >= 0 && buffer_len(&stdin_buffer) > 0)
Jan F. Chadima 3b545b
 			FD_SET(fdin, *writesetp);
Jan F. Chadima 3b545b
 	}
Jan F. Chadima 3b545b
 	notify_prepare(*readsetp);
Petr Lautrbach 44f0ac
@@ -477,7 +477,7 @@ process_output(fd_set *writeset)
Jan F. Chadima 3b545b
 	int len;
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	/* Write buffered data to program stdin. */
Jan F. Chadima 3b545b
-	if (!compat20 && fdin != -1 && FD_ISSET(fdin, writeset)) {
Jan F. Chadima 3b545b
+	if (!compat20 && fdin >= 0 && FD_ISSET(fdin, writeset)) {
Jan F. Chadima 3b545b
 		data = buffer_ptr(&stdin_buffer);
Jan F. Chadima 3b545b
 		dlen = buffer_len(&stdin_buffer);
Jan F. Chadima 3b545b
 		len = write(fdin, data, dlen);
Petr Lautrbach 44f0ac
@@ -590,7 +590,7 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
Jan F. Chadima 3b545b
 	set_nonblock(fdin);
Jan F. Chadima 3b545b
 	set_nonblock(fdout);
Jan F. Chadima 3b545b
 	/* we don't have stderr for interactive terminal sessions, see below */
Jan F. Chadima 3b545b
-	if (fderr != -1)
Jan F. Chadima 3b545b
+	if (fderr >= 0)
Jan F. Chadima 3b545b
 		set_nonblock(fderr);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	if (!(datafellows & SSH_BUG_IGNOREMSG) && isatty(fdin))
Petr Lautrbach 44f0ac
@@ -614,7 +614,7 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
Jan F. Chadima 3b545b
 	max_fd = MAX(connection_in, connection_out);
Jan F. Chadima 3b545b
 	max_fd = MAX(max_fd, fdin);
Jan F. Chadima 3b545b
 	max_fd = MAX(max_fd, fdout);
Jan F. Chadima 3b545b
-	if (fderr != -1)
Jan F. Chadima 3b545b
+	if (fderr >= 0)
Jan F. Chadima 3b545b
 		max_fd = MAX(max_fd, fderr);
Jan F. Chadima 3b545b
 #endif
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -644,7 +644,7 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
Jan F. Chadima 3b545b
 		 * If we have received eof, and there is no more pending
Jan F. Chadima 3b545b
 		 * input data, cause a real eof by closing fdin.
Jan F. Chadima 3b545b
 		 */
Jan F. Chadima 3b545b
-		if (stdin_eof && fdin != -1 && buffer_len(&stdin_buffer) == 0) {
Jan F. Chadima 3b545b
+		if (stdin_eof && fdin >= 0 && buffer_len(&stdin_buffer) == 0) {
Jan F. Chadima 3b545b
 			if (fdin != fdout)
Jan F. Chadima 3b545b
 				close(fdin);
Jan F. Chadima 3b545b
 			else
Petr Lautrbach 44f0ac
@@ -740,15 +740,15 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
Jan F. Chadima 3b545b
 	buffer_free(&stderr_buffer);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	/* Close the file descriptors. */
Jan F. Chadima 3b545b
-	if (fdout != -1)
Jan F. Chadima 3b545b
+	if (fdout >= 0)
Jan F. Chadima 3b545b
 		close(fdout);
Jan F. Chadima 3b545b
 	fdout = -1;
Jan F. Chadima 3b545b
 	fdout_eof = 1;
Jan F. Chadima 3b545b
-	if (fderr != -1)
Jan F. Chadima 3b545b
+	if (fderr >= 0)
Jan F. Chadima 3b545b
 		close(fderr);
Jan F. Chadima 3b545b
 	fderr = -1;
Jan F. Chadima 3b545b
 	fderr_eof = 1;
Jan F. Chadima 3b545b
-	if (fdin != -1)
Jan F. Chadima 3b545b
+	if (fdin >= 0)
Jan F. Chadima 3b545b
 		close(fdin);
Jan F. Chadima 3b545b
 	fdin = -1;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -947,7 +947,7 @@ server_input_window_size(int type, u_int32_t seq, void *ctxt)
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	debug("Window change received.");
Jan F. Chadima 3b545b
 	packet_check_eom();
Jan F. Chadima 3b545b
-	if (fdin != -1)
Jan F. Chadima 3b545b
+	if (fdin >= 0)
Jan F. Chadima 3b545b
 		pty_change_window_size(fdin, row, col, xpixel, ypixel);
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jakub Jelen 580f98
@@ -1039,7 +1039,7 @@ server_request_tun(void)
Jan F. Chadima 3b545b
 	}
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 	tun = packet_get_int();
Jan F. Chadima 3b545b
-	if (forced_tun_device != -1) {
Jan F. Chadima 3b545b
+	if (forced_tun_device >= 0) {
Jan F. Chadima 3b545b
 		if (tun != SSH_TUNID_ANY && forced_tun_device != tun)
Jan F. Chadima 3b545b
 			goto done;
Jan F. Chadima 3b545b
 		tun = forced_tun_device;
Petr Lautrbach 44f0ac
diff --git a/sftp-client.c b/sftp-client.c
Jakub Jelen 580f98
index 990b58d..3d0f22b 100644
Petr Lautrbach 44f0ac
--- a/sftp-client.c
Petr Lautrbach 44f0ac
+++ b/sftp-client.c
Petr Lautrbach 44f0ac
@@ -151,7 +151,7 @@ get_msg(struct sftp_conn *conn, Buffer *m)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 static void
Jan F. Chadima 3b545b
-send_string_request(struct sftp_conn *conn, u_int id, u_int code, char *s,
Jan F. Chadima 3b545b
+send_string_request(struct sftp_conn *conn, u_int id, u_int code, const char *s,
Jan F. Chadima 3b545b
     u_int len)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Petr Lautrbach 44f0ac
@@ -167,7 +167,7 @@ send_string_request(struct sftp_conn *conn, u_int id, u_int code, char *s,
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 static void
Jan F. Chadima 3b545b
 send_string_attrs_request(struct sftp_conn *conn, u_int id, u_int code,
Jan F. Chadima 3b545b
-    char *s, u_int len, Attrib *a)
Jan F. Chadima 3b545b
+    const char *s, u_int len, Attrib *a)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -429,7 +429,7 @@ sftp_proto_version(struct sftp_conn *conn)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_close(struct sftp_conn *conn, char *handle, u_int handle_len)
Jan F. Chadima 3b545b
+do_close(struct sftp_conn *conn, const char *handle, u_int handle_len)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int id, status;
Jan F. Chadima 3b545b
 	Buffer msg;
Petr Lautrbach 44f0ac
@@ -454,7 +454,7 @@ do_close(struct sftp_conn *conn, char *handle, u_int handle_len)
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 static int
Petr Lautrbach 44f0ac
-do_lsreaddir(struct sftp_conn *conn, char *path, int print_flag,
Petr Lautrbach 44f0ac
+do_lsreaddir(struct sftp_conn *conn, const char *path, int print_flag,
Jan F. Chadima 3b545b
     SFTP_DIRENT ***dir)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Petr Lautrbach 44f0ac
@@ -577,7 +577,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int print_flag,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_readdir(struct sftp_conn *conn, char *path, SFTP_DIRENT ***dir)
Jan F. Chadima 3b545b
+do_readdir(struct sftp_conn *conn, const char *path, SFTP_DIRENT ***dir)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	return(do_lsreaddir(conn, path, 0, dir));
Jan F. Chadima 3b545b
 }
Petr Lautrbach 44f0ac
@@ -597,7 +597,7 @@ void free_sftp_dirents(SFTP_DIRENT **s)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_rm(struct sftp_conn *conn, char *path)
Jan F. Chadima 3b545b
+do_rm(struct sftp_conn *conn, const char *path)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int status, id;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -612,7 +612,7 @@ do_rm(struct sftp_conn *conn, char *path)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Petr Lautrbach 44f0ac
-do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int print_flag)
Petr Lautrbach 44f0ac
+do_mkdir(struct sftp_conn *conn, const char *path, Attrib *a, int print_flag)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int status, id;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -628,7 +628,7 @@ do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int print_flag)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_rmdir(struct sftp_conn *conn, char *path)
Jan F. Chadima 3b545b
+do_rmdir(struct sftp_conn *conn, const char *path)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int status, id;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -644,7 +644,7 @@ do_rmdir(struct sftp_conn *conn, char *path)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 Attrib *
Jan F. Chadima 3b545b
-do_stat(struct sftp_conn *conn, char *path, int quiet)
Jan F. Chadima 3b545b
+do_stat(struct sftp_conn *conn, const char *path, int quiet)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int id;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -658,7 +658,7 @@ do_stat(struct sftp_conn *conn, char *path, int quiet)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 Attrib *
Jan F. Chadima 3b545b
-do_lstat(struct sftp_conn *conn, char *path, int quiet)
Jan F. Chadima 3b545b
+do_lstat(struct sftp_conn *conn, const char *path, int quiet)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int id;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -679,7 +679,7 @@ do_lstat(struct sftp_conn *conn, char *path, int quiet)
Petr Lautrbach 44f0ac
 
Petr Lautrbach 44f0ac
 #ifdef notyet
Petr Lautrbach 44f0ac
 Attrib *
Petr Lautrbach 44f0ac
-do_fstat(struct sftp_conn *conn, char *handle, u_int handle_len, int quiet)
Petr Lautrbach 44f0ac
+do_fstat(struct sftp_conn *conn, const char *handle, u_int handle_len, int quiet)
Petr Lautrbach 44f0ac
 {
Petr Lautrbach 44f0ac
 	u_int id;
Petr Lautrbach 44f0ac
 
Petr Lautrbach 44f0ac
@@ -692,7 +692,7 @@ do_fstat(struct sftp_conn *conn, char *handle, u_int handle_len, int quiet)
Jan F. Chadima 3b545b
 #endif
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_setstat(struct sftp_conn *conn, char *path, Attrib *a)
Jan F. Chadima 3b545b
+do_setstat(struct sftp_conn *conn, const char *path, Attrib *a)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int status, id;
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
@@ -709,7 +709,7 @@ do_setstat(struct sftp_conn *conn, char *path, Attrib *a)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_fsetstat(struct sftp_conn *conn, char *handle, u_int handle_len,
Jan F. Chadima 3b545b
+do_fsetstat(struct sftp_conn *conn, const char *handle, u_int handle_len,
Jan F. Chadima 3b545b
     Attrib *a)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	u_int status, id;
Petr Lautrbach 44f0ac
@@ -726,7 +726,7 @@ do_fsetstat(struct sftp_conn *conn, char *handle, u_int handle_len,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 char *
Jan F. Chadima 3b545b
-do_realpath(struct sftp_conn *conn, char *path)
Jan F. Chadima 3b545b
+do_realpath(struct sftp_conn *conn, const char *path)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Jan F. Chadima 3b545b
 	u_int type, expected_id, count, id;
Petr Lautrbach 44f0ac
@@ -775,7 +775,7 @@ do_realpath(struct sftp_conn *conn, char *path)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Petr Lautrbach 44f0ac
-do_rename(struct sftp_conn *conn, char *oldpath, char *newpath,
Petr Lautrbach 44f0ac
+do_rename(struct sftp_conn *conn, const char *oldpath, const char *newpath,
Petr Lautrbach 44f0ac
     int force_legacy)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Petr Lautrbach 44f0ac
@@ -811,7 +811,7 @@ do_rename(struct sftp_conn *conn, char *oldpath, char *newpath,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_hardlink(struct sftp_conn *conn, char *oldpath, char *newpath)
Jan F. Chadima 3b545b
+do_hardlink(struct sftp_conn *conn, const char *oldpath, const char *newpath)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Jan F. Chadima 3b545b
 	u_int status, id;
Petr Lautrbach 44f0ac
@@ -844,7 +844,7 @@ do_hardlink(struct sftp_conn *conn, char *oldpath, char *newpath)
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_symlink(struct sftp_conn *conn, char *oldpath, char *newpath)
Jan F. Chadima 3b545b
+do_symlink(struct sftp_conn *conn, const char *oldpath, const char *newpath)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Buffer msg;
Jan F. Chadima 3b545b
 	u_int status, id;
Petr Lautrbach 44f0ac
@@ -876,7 +876,7 @@ do_symlink(struct sftp_conn *conn, char *oldpath, char *newpath)
Petr Lautrbach 44f0ac
 }
Petr Lautrbach 44f0ac
 
Petr Lautrbach 44f0ac
 int
Petr Lautrbach 44f0ac
-do_fsync(struct sftp_conn *conn, char *handle, u_int handle_len)
Petr Lautrbach 44f0ac
+do_fsync(struct sftp_conn *conn, const char *handle, u_int handle_len)
Petr Lautrbach 44f0ac
 {
Petr Lautrbach 44f0ac
 	Buffer msg;
Petr Lautrbach 44f0ac
 	u_int status, id;
Petr Lautrbach 44f0ac
@@ -907,7 +907,7 @@ do_fsync(struct sftp_conn *conn, char *handle, u_int handle_len)
Petr Lautrbach 44f0ac
 
Petr Lautrbach 44f0ac
 #ifdef notyet
Petr Lautrbach 44f0ac
 char *
Petr Lautrbach 44f0ac
-do_readlink(struct sftp_conn *conn, char *path)
Petr Lautrbach 44f0ac
+do_readlink(struct sftp_conn *conn, const char *path)
Petr Lautrbach 44f0ac
 {
Petr Lautrbach 44f0ac
 	Buffer msg;
Petr Lautrbach 44f0ac
 	u_int type, expected_id, count, id;
Petr Lautrbach 44f0ac
@@ -1010,7 +1010,7 @@ do_fstatvfs(struct sftp_conn *conn, const char *handle, u_int handle_len,
Petr Lautrbach 44f0ac
 
Petr Lautrbach 44f0ac
 static void
Petr Lautrbach 44f0ac
 send_read_request(struct sftp_conn *conn, u_int id, u_int64_t offset,
Petr Lautrbach 44f0ac
-    u_int len, char *handle, u_int handle_len)
Petr Lautrbach 44f0ac
+    u_int len, const char *handle, u_int handle_len)
Petr Lautrbach 44f0ac
 {
Petr Lautrbach 44f0ac
 	Buffer msg;
Petr Lautrbach 44f0ac
 
Petr Lautrbach 44f0ac
@@ -1026,7 +1026,7 @@ send_read_request(struct sftp_conn *conn, u_int id, u_int64_t offset,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
Jan F. Chadima 3b545b
+do_download(struct sftp_conn *conn, const char *remote_path, const char *local_path,
Petr Lautrbach 44f0ac
     Attrib *a, int preserve_flag, int resume_flag, int fsync_flag)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	Attrib junk;
Petr Lautrbach 44f0ac
@@ -1308,7 +1308,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 static int
Petr Lautrbach 44f0ac
-download_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
Petr Lautrbach 44f0ac
+download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, int depth,
Petr Lautrbach 44f0ac
     Attrib *dirattrib, int preserve_flag, int print_flag, int resume_flag,
Petr Lautrbach 44f0ac
     int fsync_flag)
Jan F. Chadima 3b545b
 {
Petr Lautrbach 44f0ac
@@ -1400,7 +1400,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-download_dir(struct sftp_conn *conn, char *src, char *dst,
Jan F. Chadima 3b545b
+download_dir(struct sftp_conn *conn, const char *src, const char *dst,
Petr Lautrbach 44f0ac
     Attrib *dirattrib, int preserve_flag, int print_flag,
Petr Lautrbach 44f0ac
     int resume_flag, int fsync_flag)
Jan F. Chadima 3b545b
 {
Petr Lautrbach 44f0ac
@@ -1419,7 +1419,7 @@ download_dir(struct sftp_conn *conn, char *src, char *dst,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Jan F. Chadima 3b545b
-do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
Jan F. Chadima 3b545b
+do_upload(struct sftp_conn *conn, const char *local_path, const char *remote_path,
Jakub Jelen 580f98
     int preserve_flag, int resume, int fsync_flag)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	int local_fd;
Jakub Jelen 580f98
@@ -1628,7 +1628,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 static int
Petr Lautrbach 44f0ac
-upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
Petr Lautrbach 44f0ac
+upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, int depth,
Jakub Jelen 580f98
     int preserve_flag, int print_flag, int resume, int fsync_flag)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	int ret = 0, status;
Jakub Jelen 580f98
@@ -1721,7 +1721,7 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 int
Petr Lautrbach 44f0ac
-upload_dir(struct sftp_conn *conn, char *src, char *dst, int preserve_flag,
Petr Lautrbach 44f0ac
+upload_dir(struct sftp_conn *conn, const char *src, const char *dst, int preserve_flag,
Jakub Jelen 580f98
     int print_flag, int resume, int fsync_flag)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	char *dst_canon;
Jakub Jelen 580f98
@@ -1740,7 +1740,7 @@ upload_dir(struct sftp_conn *conn, char *src, char *dst, int preserve_flag,
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 char *
Jan F. Chadima 3b545b
-path_append(char *p1, char *p2)
Jan F. Chadima 3b545b
+path_append(const char *p1, const char *p2)
Jan F. Chadima 3b545b
 {
Jan F. Chadima 3b545b
 	char *ret;
Jan F. Chadima 3b545b
 	size_t len = strlen(p1) + strlen(p2) + 2;
Petr Lautrbach 44f0ac
diff --git a/sftp-client.h b/sftp-client.h
Jakub Jelen 580f98
index 967840b..ffbcade 100644
Petr Lautrbach 44f0ac
--- a/sftp-client.h
Petr Lautrbach 44f0ac
+++ b/sftp-client.h
Petr Lautrbach 44f0ac
@@ -56,79 +56,79 @@ struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
Jan F. Chadima 3b545b
 u_int sftp_proto_version(struct sftp_conn *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Close file referred to by 'handle' */
Jan F. Chadima 3b545b
-int do_close(struct sftp_conn *, char *, u_int);
Jan F. Chadima 3b545b
+int do_close(struct sftp_conn *, const char *, u_int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Read contents of 'path' to NULL-terminated array 'dir' */
Jan F. Chadima 3b545b
-int do_readdir(struct sftp_conn *, char *, SFTP_DIRENT ***);
Jan F. Chadima 3b545b
+int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
Jan F. Chadima 3b545b
 void free_sftp_dirents(SFTP_DIRENT **);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Delete file 'path' */
Jan F. Chadima 3b545b
-int do_rm(struct sftp_conn *, char *);
Jan F. Chadima 3b545b
+int do_rm(struct sftp_conn *, const char *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Create directory 'path' */
Jan F. Chadima 3b545b
-int do_mkdir(struct sftp_conn *, char *, Attrib *, int);
Jan F. Chadima 3b545b
+int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Remove directory 'path' */
Jan F. Chadima 3b545b
-int do_rmdir(struct sftp_conn *, char *);
Jan F. Chadima 3b545b
+int do_rmdir(struct sftp_conn *, const char *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Get file attributes of 'path' (follows symlinks) */
Jan F. Chadima 3b545b
-Attrib *do_stat(struct sftp_conn *, char *, int);
Jan F. Chadima 3b545b
+Attrib *do_stat(struct sftp_conn *, const char *, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Get file attributes of 'path' (does not follow symlinks) */
Jan F. Chadima 3b545b
-Attrib *do_lstat(struct sftp_conn *, char *, int);
Jan F. Chadima 3b545b
+Attrib *do_lstat(struct sftp_conn *, const char *, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Set file attributes of 'path' */
Jan F. Chadima 3b545b
-int do_setstat(struct sftp_conn *, char *, Attrib *);
Jan F. Chadima 3b545b
+int do_setstat(struct sftp_conn *, const char *, Attrib *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Set file attributes of open file 'handle' */
Jan F. Chadima 3b545b
-int do_fsetstat(struct sftp_conn *, char *, u_int, Attrib *);
Jan F. Chadima 3b545b
+int do_fsetstat(struct sftp_conn *, const char *, u_int, Attrib *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Canonicalise 'path' - caller must free result */
Jan F. Chadima 3b545b
-char *do_realpath(struct sftp_conn *, char *);
Jan F. Chadima 3b545b
+char *do_realpath(struct sftp_conn *, const char *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Get statistics for filesystem hosting file at "path" */
Jan F. Chadima 3b545b
 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Rename 'oldpath' to 'newpath' */
Petr Lautrbach 44f0ac
-int do_rename(struct sftp_conn *, char *, char *m, int force_legacy);
Petr Lautrbach 44f0ac
+int do_rename(struct sftp_conn *, const char *, const char *m, int force_legacy);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Link 'oldpath' to 'newpath' */
Jan F. Chadima 3b545b
-int do_hardlink(struct sftp_conn *, char *, char *);
Jan F. Chadima 3b545b
+int do_hardlink(struct sftp_conn *, const char *, const char *);
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
 /* Rename 'oldpath' to 'newpath' */
Jan F. Chadima 3b545b
-int do_symlink(struct sftp_conn *, char *, char *);
Jan F. Chadima 3b545b
+int do_symlink(struct sftp_conn *, const char *, const char *);
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
 /* Call fsync() on open file 'handle' */
Petr Lautrbach 44f0ac
-int do_fsync(struct sftp_conn *conn, char *, u_int);
Petr Lautrbach 44f0ac
+int do_fsync(struct sftp_conn *conn, const char *, u_int);
Jan F. Chadima 3b545b
 
Petr Lautrbach 44f0ac
 /*
Jan F. Chadima 3b545b
  * Download 'remote_path' to 'local_path'. Preserve permissions and times
Jan F. Chadima 3b545b
  * if 'pflag' is set
Jan F. Chadima 3b545b
  */
Petr Lautrbach 44f0ac
-int do_download(struct sftp_conn *, char *, char *, Attrib *, int, int, int);
Petr Lautrbach 44f0ac
+int do_download(struct sftp_conn *, const char *, const char *, Attrib *, int, int, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /*
Jan F. Chadima 3b545b
  * Recursively download 'remote_directory' to 'local_directory'. Preserve 
Jan F. Chadima 3b545b
  * times if 'pflag' is set
Jan F. Chadima 3b545b
  */
Petr Lautrbach 44f0ac
-int download_dir(struct sftp_conn *, char *, char *, Attrib *, int,
Petr Lautrbach 44f0ac
+int download_dir(struct sftp_conn *, const char *, const char *, Attrib *, int,
Petr Lautrbach 44f0ac
     int, int, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /*
Jan F. Chadima 3b545b
  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
Jan F. Chadima 3b545b
  * if 'pflag' is set
Jan F. Chadima 3b545b
  */
Jakub Jelen 580f98
-int do_upload(struct sftp_conn *, char *, char *, int, int, int);
Jakub Jelen 580f98
+int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /*
Jan F. Chadima 3b545b
  * Recursively upload 'local_directory' to 'remote_directory'. Preserve 
Jan F. Chadima 3b545b
  * times if 'pflag' is set
Jan F. Chadima 3b545b
  */
Jakub Jelen 580f98
-int upload_dir(struct sftp_conn *, char *, char *, int, int, int, int);
Jakub Jelen 580f98
+int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int, int);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 /* Concatenate paths, taking care of slashes. Caller must free result. */
Jan F. Chadima 3b545b
-char *path_append(char *, char *);
Jan F. Chadima 3b545b
+char *path_append(const char *, const char *);
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 #endif
Petr Lautrbach 44f0ac
diff --git a/sftp.c b/sftp.c
Jakub Jelen 580f98
index ff4d63d..4439100 100644
Petr Lautrbach 44f0ac
--- a/sftp.c
Petr Lautrbach 44f0ac
+++ b/sftp.c
Jakub Jelen 580f98
@@ -220,7 +220,7 @@ killchild(int signo)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	if (sshpid > 1) {
Petr Lautrbach 84822b
 		kill(sshpid, SIGTERM);
Petr Lautrbach 84822b
-		waitpid(sshpid, NULL, 0);
Petr Lautrbach 84822b
+		(void) waitpid(sshpid, NULL, 0);
Petr Lautrbach 84822b
 	}
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 	_exit(1);
Jakub Jelen 580f98
@@ -332,7 +332,7 @@ local_do_ls(const char *args)
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 /* Strip one path (usually the pwd) from the start of another */
Petr Lautrbach 84822b
 static char *
Petr Lautrbach 84822b
-path_strip(char *path, char *strip)
Petr Lautrbach 84822b
+path_strip(const char *path, const char *strip)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	size_t len;
Petr Lautrbach 84822b
 
Jakub Jelen 580f98
@@ -350,7 +350,7 @@ path_strip(char *path, char *strip)
Petr Lautrbach 84822b
 }
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 static char *
Petr Lautrbach 84822b
-make_absolute(char *p, char *pwd)
Petr Lautrbach 84822b
+make_absolute(char *p, const char *pwd)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	char *abs_str;
Petr Lautrbach 84822b
 
Jakub Jelen 580f98
@@ -548,7 +548,7 @@ parse_no_flags(const char *cmd, char **argv, int argc)
Petr Lautrbach 84822b
 }
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-is_dir(char *path)
Petr Lautrbach 84822b
+is_dir(const char *path)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	struct stat sb;
Petr Lautrbach 84822b
 
Jakub Jelen 580f98
@@ -560,7 +560,7 @@ is_dir(char *path)
Petr Lautrbach 84822b
 }
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-remote_is_dir(struct sftp_conn *conn, char *path)
Petr Lautrbach 84822b
+remote_is_dir(struct sftp_conn *conn, const char *path)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	Attrib *a;
Petr Lautrbach 84822b
 
Jakub Jelen 580f98
@@ -574,7 +574,7 @@ remote_is_dir(struct sftp_conn *conn, char *path)
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-pathname_is_dir(char *pathname)
Petr Lautrbach 84822b
+pathname_is_dir(const char *pathname)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	size_t l = strlen(pathname);
Petr Lautrbach 84822b
 
Jakub Jelen 580f98
@@ -582,7 +582,7 @@ pathname_is_dir(char *pathname)
Petr Lautrbach 84822b
 }
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd,
Petr Lautrbach 84822b
+process_get(struct sftp_conn *conn, const char *src, const char *dst, const char *pwd,
Petr Lautrbach 44f0ac
     int pflag, int rflag, int resume, int fflag)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	char *abs_src = NULL;
Jakub Jelen 580f98
@@ -666,7 +666,7 @@ out:
Petr Lautrbach 84822b
 }
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd,
Petr Lautrbach 84822b
+process_put(struct sftp_conn *conn, const char *src, const char *dst, const char *pwd,
Jakub Jelen 580f98
     int pflag, int rflag, int resume, int fflag)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	char *tmp_dst = NULL;
Jakub Jelen 580f98
@@ -776,7 +776,7 @@ sdirent_comp(const void *aa, const void *bb)
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 /* sftp ls.1 replacement for directories */
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
Petr Lautrbach 84822b
+do_ls_dir(struct sftp_conn *conn, const char *path, const char *strip_path, int lflag)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	int n;
Petr Lautrbach 84822b
 	u_int c = 1, colspace = 0, columns = 1;
Jakub Jelen 580f98
@@ -861,7 +861,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 /* sftp ls.1 replacement which handles path globs */
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
Petr Lautrbach 84822b
+do_globbed_ls(struct sftp_conn *conn, const char *path, const char *strip_path,
Petr Lautrbach 84822b
     int lflag)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	char *fname, *lname;
Jakub Jelen 580f98
@@ -946,7 +946,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
Petr Lautrbach 84822b
 }
Petr Lautrbach 84822b
 
Petr Lautrbach 84822b
 static int
Petr Lautrbach 84822b
-do_df(struct sftp_conn *conn, char *path, int hflag, int iflag)
Petr Lautrbach 84822b
+do_df(struct sftp_conn *conn, const char *path, int hflag, int iflag)
Petr Lautrbach 84822b
 {
Petr Lautrbach 84822b
 	struct sftp_statvfs st;
Petr Lautrbach 84822b
 	char s_used[FMT_SCALED_STRSIZE];
Petr Lautrbach 44f0ac
diff --git a/ssh-agent.c b/ssh-agent.c
Jakub Jelen 580f98
index c8036c8..4da3bb6 100644
Petr Lautrbach 44f0ac
--- a/ssh-agent.c
Petr Lautrbach 44f0ac
+++ b/ssh-agent.c
Jakub Jelen 580f98
@@ -1056,8 +1056,8 @@ main(int ac, char **av)
Jan F. Chadima ea97ff
 	sanitise_stdfd();
Jan F. Chadima ea97ff
 
Jan F. Chadima ea97ff
 	/* drop */
Jan F. Chadima ea97ff
-	setegid(getgid());
Jan F. Chadima ea97ff
-	setgid(getgid());
Jan F. Chadima ea97ff
+	(void) setegid(getgid());
Jan F. Chadima ea97ff
+	(void) setgid(getgid());
Jan F. Chadima ea97ff
 
Jan F. Chadima ea97ff
 #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
Jan F. Chadima ea97ff
 	/* Disable ptrace on Linux without sgid bit */
Jakub Jelen 580f98
diff --git a/ssh-keygen.c b/ssh-keygen.c
Jakub Jelen 580f98
index 64fa217..635e8fd 100644
Jakub Jelen 580f98
--- a/ssh-keygen.c
Jakub Jelen 580f98
+++ b/ssh-keygen.c
Jakub Jelen 580f98
@@ -687,11 +687,11 @@ do_convert_from(struct passwd *pw)
Jakub Jelen 580f98
 		fatal("%s: unknown key format %d", __func__, convert_format);
Jakub Jelen 580f98
 	}
Jakub Jelen 580f98
 
Jakub Jelen 580f98
-	if (!private)
Jakub Jelen 580f98
+	if (!private) {
Jakub Jelen 580f98
 		ok = key_write(k, stdout);
Jakub Jelen 580f98
 		if (ok)
Jakub Jelen 580f98
 			fprintf(stdout, "\n");
Jakub Jelen 580f98
-	else {
Jakub Jelen 580f98
+	} else {
Jakub Jelen 580f98
 		switch (k->type) {
Jakub Jelen 580f98
 		case KEY_DSA:
Jakub Jelen 580f98
 			ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL,
Petr Lautrbach 44f0ac
diff --git a/sshd.c b/sshd.c
Jakub Jelen 580f98
index 783abe3..eaade2a 100644
Petr Lautrbach 44f0ac
--- a/sshd.c
Petr Lautrbach 44f0ac
+++ b/sshd.c
Petr Lautrbach 44f0ac
@@ -771,8 +771,10 @@ privsep_preauth(Authctxt *authctxt)
Jan F. Chadima cff1d0
 		if (getuid() == 0 || geteuid() == 0)
Jan F. Chadima cff1d0
 			privsep_preauth_child();
Jan F. Chadima cff1d0
 		setproctitle("%s", "[net]");
Jan F. Chadima cff1d0
-		if (box != NULL)
Jan F. Chadima cff1d0
+		if (box != NULL) {
Jan F. Chadima cff1d0
 			ssh_sandbox_child(box);
Petr Lautrbach 84822b
+			free(box);
Jan F. Chadima cff1d0
+		}
Jan F. Chadima cff1d0
 
Jan F. Chadima cff1d0
 		return 0;
Jan F. Chadima cff1d0
 	}
Jakub Jelen 580f98
@@ -1458,6 +1460,9 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
Jan F. Chadima 3b545b
 		if (num_listen_socks < 0)
Jan F. Chadima 3b545b
 			break;
Jan F. Chadima 3b545b
 	}
Jan F. Chadima 3b545b
+
Jan F. Chadima 3b545b
+	if (fdset != NULL)
Petr Lautrbach 84822b
+		free(fdset);
Jan F. Chadima 3b545b
 }
Jan F. Chadima 3b545b
 
Jan F. Chadima 3b545b
 
Jakub Jelen 580f98
diff --git a/sshkey.c b/sshkey.c
Jakub Jelen 580f98
index 5e3d97f..dae8270 100644
Jakub Jelen 580f98
--- a/sshkey.c
Jakub Jelen 580f98
+++ b/sshkey.c
Jakub Jelen 580f98
@@ -54,6 +54,7 @@
Jakub Jelen 580f98
 #include "digest.h"
Jakub Jelen 580f98
 #define SSHKEY_INTERNAL
Jakub Jelen 580f98
 #include "sshkey.h"
Jakub Jelen 580f98
+#include "log.h"
Jakub Jelen 580f98
 
Jakub Jelen 580f98
 /* openssh private key file format */
Jakub Jelen 580f98
 #define MARK_BEGIN		"-----BEGIN OPENSSH PRIVATE KEY-----\n"