- djm@cvs.openbsd.org 2001/02/06 23:30:28
     [sftp-client.c]
     replace arc4random with counter for request ids; ok markus@
diff --git a/sftp-client.c b/sftp-client.c
index e428238..e8b9007 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -29,7 +29,7 @@
 /* XXX: copy between two remote sites */
 
 #include "includes.h"
-RCSID("$OpenBSD: sftp-client.c,v 1.3 2001/02/04 15:32:25 stevesk Exp $");
+RCSID("$OpenBSD: sftp-client.c,v 1.4 2001/02/06 23:30:28 djm Exp $");
 
 #include "ssh.h"
 #include "buffer.h"
@@ -48,6 +48,9 @@
 /* XXX: what should this be? */
 #define COPY_SIZE	8192
 
+/* Message ID */
+static u_int msg_id = 1;
+
 void
 send_msg(int fd, Buffer *m)
 {
@@ -255,7 +258,7 @@
 
 	buffer_init(&msg);
 
-	id = arc4random();
+	id = msg_id++;
 	buffer_put_char(&msg, SSH2_FXP_CLOSE);
 	buffer_put_int(&msg, id);
 	buffer_put_string(&msg, handle, handle_len);
@@ -278,7 +281,7 @@
 	u_int type, id, handle_len, i, expected_id;
 	char *handle;
 
-	id = arc4random();
+	id = msg_id++;
 
 	buffer_init(&msg);
 	buffer_put_char(&msg, SSH2_FXP_OPENDIR);
@@ -295,7 +298,7 @@
 	for(;;) {
 		int count;
 
-		expected_id = ++id;
+		id = expected_id = msg_id++;
 
 		debug3("Sending SSH2_FXP_READDIR I:%d", id);
 
@@ -365,7 +368,7 @@
 
 	debug2("Sending SSH2_FXP_REMOVE \"%s\"", path);
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_request(fd_out, id, SSH2_FXP_REMOVE, path, strlen(path));
 	status = get_status(fd_in, id);
 	if (status != SSH2_FX_OK)
@@ -378,7 +381,7 @@
 {
 	u_int status, id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_attrs_request(fd_out, id, SSH2_FXP_MKDIR, path,
 	    strlen(path), a);
 
@@ -394,7 +397,7 @@
 {
 	u_int status, id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_request(fd_out, id, SSH2_FXP_RMDIR, path, strlen(path));
 
 	status = get_status(fd_in, id);
@@ -409,7 +412,7 @@
 {
 	u_int id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_request(fd_out, id, SSH2_FXP_STAT, path, strlen(path));
 	return(get_decode_stat(fd_in, id));
 }
@@ -419,7 +422,7 @@
 {
 	u_int id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_request(fd_out, id, SSH2_FXP_LSTAT, path, strlen(path));
 	return(get_decode_stat(fd_in, id));
 }
@@ -430,7 +433,7 @@
 {
 	u_int id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_request(fd_out, id, SSH2_FXP_FSTAT, handle, handle_len);
 	return(get_decode_stat(fd_in, id));
 }
@@ -440,7 +443,7 @@
 {
 	u_int status, id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_attrs_request(fd_out, id, SSH2_FXP_SETSTAT, path,
 	    strlen(path), a);
 
@@ -458,7 +461,7 @@
 {
 	u_int status, id;
 
-	id = arc4random();
+	id = msg_id++;
 	send_string_attrs_request(fd_out, id, SSH2_FXP_FSETSTAT, handle,
 	    handle_len, a);
 
@@ -477,7 +480,7 @@
 	char *filename, *longname;
 	Attrib *a;
 
-	expected_id = id = arc4random();
+	expected_id = id = msg_id++;
 	send_string_request(fd_out, id, SSH2_FXP_REALPATH, path,
 	    strlen(path));
 
@@ -525,7 +528,7 @@
 	buffer_init(&msg);
 
 	/* Send rename request */
-	id = arc4random();
+	id = msg_id++;
 	buffer_put_char(&msg, SSH2_FXP_RENAME);
 	buffer_put_int(&msg, id);
 	buffer_put_cstring(&msg, oldpath);
@@ -588,7 +591,7 @@
 	buffer_init(&msg);
 
 	/* Send open request */
-	id = arc4random();
+	id = msg_id++;
 	buffer_put_char(&msg, SSH2_FXP_OPEN);
 	buffer_put_int(&msg, id);
 	buffer_put_cstring(&msg, remote_path);
@@ -611,7 +614,7 @@
 		u_int len;
 		char *data;
 
-		expected_id = ++id;
+		id = expected_id = msg_id++;
 
 		buffer_clear(&msg);
 		buffer_put_char(&msg, SSH2_FXP_READ);
@@ -713,7 +716,7 @@
 	buffer_init(&msg);
 
 	/* Send open request */
-	id = arc4random();
+	id = msg_id++;
 	buffer_put_char(&msg, SSH2_FXP_OPEN);
 	buffer_put_int(&msg, id);
 	buffer_put_cstring(&msg, remote_path);