From a920932703ca4867f13f53ea9f7c8724802ee685 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 21 Feb 2021 14:55:25 -0800 Subject: [PATCH] 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()`. --- src/protocols/kubernetes/url.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/protocols/kubernetes/url.c b/src/protocols/kubernetes/url.c index 4bca0157..ec0e8807 100644 --- a/src/protocols/kubernetes/url.c +++ b/src/protocols/kubernetes/url.c @@ -123,10 +123,14 @@ int guac_kubernetes_append_endpoint_param(char* buffer, int length, char delimiter = '?'; if (qmark) delimiter = '&'; - /* Write the parameter to the buffer */ - int written; - written = snprintf(buffer + str_len, length - str_len, - "%c%s=%s", delimiter, param_name, escaped_param_value); + /* Advance to end of buffer, where the new parameter and delimiter need to + * be appended */ + buffer += str_len; + 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 * buffer without truncation */