You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2018/04/02 19:20:53 UTC
[20/23] guacamole-server git commit: GUACAMOLE-269: Remove
unnecessary data structure and array size, and update comments.
GUACAMOLE-269: Remove unnecessary data structure and array size, and update comments.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-server/commit/b441181c
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-server/tree/b441181c
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-server/diff/b441181c
Branch: refs/heads/master
Commit: b441181c189e3ac8baa226f2022e82d8739532e3
Parents: ea946f2
Author: Nick Couchman <vn...@apache.org>
Authored: Mon Apr 2 09:22:51 2018 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Mon Apr 2 10:43:57 2018 -0400
----------------------------------------------------------------------
src/protocols/ssh/ssh.c | 5 ++---
src/protocols/ssh/ttymode.c | 9 ++------
src/protocols/ssh/ttymode.h | 46 ++++++++++++----------------------------
3 files changed, 17 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/b441181c/src/protocols/ssh/ssh.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c
index ace5d6f..dca6208 100644
--- a/src/protocols/ssh/ssh.c
+++ b/src/protocols/ssh/ssh.c
@@ -192,8 +192,7 @@ void* ssh_client_thread(void* data) {
return NULL;
}
- const int num_tty_opcodes = 1;
- char ssh_ttymodes[(GUAC_SSH_TTY_OPCODE_SIZE * num_tty_opcodes) + 1];
+ char ssh_ttymodes[GUAC_SSH_TTYMODES_SIZE(1)];
/* Set up screen recording, if requested */
if (settings->recording_path != NULL) {
@@ -301,7 +300,7 @@ void* ssh_client_thread(void* data) {
}
/* Set up the ttymode array prior to requesting the PTY */
- int ttymodeBytes = guac_ssh_ttymodes_init(ssh_ttymodes, sizeof(ssh_ttymodes),
+ int ttymodeBytes = guac_ssh_ttymodes_init(ssh_ttymodes,
GUAC_SSH_TTY_OP_VERASE, settings->backspace, GUAC_SSH_TTY_OP_END);
if (ttymodeBytes < 1)
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Error storing TTY mode encoding \
http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/b441181c/src/protocols/ssh/ttymode.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/ttymode.c b/src/protocols/ssh/ttymode.c
index 9f60859..686cbbd 100644
--- a/src/protocols/ssh/ttymode.c
+++ b/src/protocols/ssh/ttymode.c
@@ -25,12 +25,11 @@
#include <stdlib.h>
#include <string.h>
-int guac_ssh_ttymodes_init(char opcode_array[], const int array_size,
- ...) {
+int guac_ssh_ttymodes_init(char opcode_array[], ...) {
/* Initialize the variable argument list. */
va_list args;
- va_start(args, array_size);
+ va_start(args, opcode_array);
/* Initialize array pointer and byte counter. */
char *current = opcode_array;
@@ -39,10 +38,6 @@ int guac_ssh_ttymodes_init(char opcode_array[], const int array_size,
/* Loop through variable argument list. */
while (true) {
- /* Check to make sure we don't overrun array. */
- if (bytes >= array_size)
- return -1;
-
/* Next argument should be an opcode. */
char opcode = (char)va_arg(args, int);
*(current++) = opcode;
http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/b441181c/src/protocols/ssh/ttymode.h
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/ttymode.h b/src/protocols/ssh/ttymode.h
index 96bf0b4..648d13e 100644
--- a/src/protocols/ssh/ttymode.h
+++ b/src/protocols/ssh/ttymode.h
@@ -46,46 +46,27 @@
#define GUAC_SSH_TTY_OP_VERASE 3
/**
- * The SSH protocol attempts to configure the remote
- * terminal by sending pairs of opcodes and values, as
- * described in Section 8 of RFC 4254. These are
- * comprised of a single byte opcode and a 4-byte
- * value. This data structure stores a single opcode
- * and value pair.
+ * Macro for calculating the number of bytes required
+ * to pass a given number of opcodes, which calculates
+ * the size of the number of opcodes plus the single byte
+ * end opcode.
*/
-typedef struct guac_ssh_ttymode {
-
- /**
- * The single byte opcode for defining the TTY
- * encoding setting for the remote terminal. The
- * stadard codes are defined in Section 8 of
- * the SSH RFC (4254).
- */
- char opcode;
-
- /**
- * The four byte value of the setting for the
- * defined opcode.
- */
- uint32_t value;
-
-} guac_ssh_ttymode;
+#define GUAC_SSH_TTYMODES_SIZE(num_opcodes) ((GUAC_SSH_TTY_OPCODE_SIZE * num_opcodes) + 1)
/**
* Opcodes and value pairs are passed to the SSH connection
* in a single array, beginning with the opcode and followed
* by a four byte value, repeating until the end opcode is
- * encountered. This function takes the array, the array
- * size, and a variable number of opcode and value pair
- * arguments and puts them in the array expected by the
- * SSH connection.
+ * encountered. This function takes the array that will be
+ * sent and a variable number of opcode and value pair
+ * arguments and places the opcode and values in the array
+ * as expected by the SSH connection.
*
* @param opcode_array
* Pointer to the opcode array that will ultimately
- * be passed to the SSH connection.
- *
- * @param array_size
- * Size, in bytes, of the array.
+ * be passed to the SSH connection. The array must
+ * be size to handle 5 bytes for each opcode and value
+ * pair, plus one additional byte for the end opcode.
*
* @params ...
* A variable number of opcode and value pairs
@@ -95,7 +76,6 @@ typedef struct guac_ssh_ttymode {
* Number of bytes written to the array, or zero
* if a failure occurs.
*/
-int guac_ssh_ttymodes_init(char opcode_array[], const int array_size,
- ...);
+int guac_ssh_ttymodes_init(char opcode_array[], ...);
#endif