GUACAMOLE-1174: Correct logic detecting truncation of appended parameter.

The previous implementation passed `length - str_len` to `snprintf()`,
yet compared the return value to `length`. This is incorrect, as
`length` is not the buffer size provided to `snprintf()`.
This commit is contained in:
Michael Jumper 2021-02-21 14:55:25 -08:00
parent c7935736da
commit a920932703

View File

@ -123,10 +123,14 @@ int guac_kubernetes_append_endpoint_param(char* buffer, int length,
char delimiter = '?'; char delimiter = '?';
if (qmark) delimiter = '&'; if (qmark) delimiter = '&';
/* Write the parameter to the buffer */ /* Advance to end of buffer, where the new parameter and delimiter need to
int written; * be appended */
written = snprintf(buffer + str_len, length - str_len, buffer += str_len;
"%c%s=%s", delimiter, param_name, escaped_param_value); length -= str_len;
/* Write the parameter and delimiter to the buffer */
int written = snprintf(buffer, length, "%c%s=%s", delimiter,
param_name, escaped_param_value);
/* The parameter was successfully added if it was written to the given /* The parameter was successfully added if it was written to the given
* buffer without truncation */ * buffer without truncation */