]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
socks_gssapi: switch to dynbuf from buffer with strcpy
authorDaniel Stenberg <daniel@haxx.se>
Thu, 26 Sep 2024 12:52:33 +0000 (14:52 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 26 Sep 2024 21:24:14 +0000 (23:24 +0200)
Closes #15057

lib/socks_gssapi.c

index 3dc01887c624eb1ccee717dced5629af779068c1..f6fd55dcec9cbd129ec8fe6530e74b1f64576ef3 100644 (file)
@@ -42,6 +42,8 @@
 #include "curl_memory.h"
 #include "memdebug.h"
 
+#define MAX_GSS_LEN 1024
+
 static gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;
 
 /*
@@ -56,10 +58,9 @@ static int check_gss_err(struct Curl_easy *data,
     OM_uint32 maj_stat, min_stat;
     OM_uint32 msg_ctx = 0;
     gss_buffer_desc status_string = GSS_C_EMPTY_BUFFER;
-    char buf[1024];
-    size_t len;
+    struct dynbuf dbuf;
 
-    len = 0;
+    Curl_dyn_init(&dbuf, MAX_GSS_LEN);
     msg_ctx = 0;
     while(!msg_ctx) {
       /* convert major status code (GSS-API error) to text */
@@ -68,19 +69,16 @@ static int check_gss_err(struct Curl_easy *data,
                                     GSS_C_NULL_OID,
                                     &msg_ctx, &status_string);
       if(maj_stat == GSS_S_COMPLETE) {
-        if(sizeof(buf) > len + status_string.length + 1) {
-          strcpy(buf + len, (char *) status_string.value);
-          len += status_string.length;
-        }
+        if(Curl_dyn_addn(&dbuf, status_string.value,
+                         status_string.length))
+          return 1; /* error */
         gss_release_buffer(&min_stat, &status_string);
         break;
       }
       gss_release_buffer(&min_stat, &status_string);
     }
-    if(sizeof(buf) > len + 3) {
-      strcpy(buf + len, ".\n");
-      len += 2;
-    }
+    if(Curl_dyn_addn(&dbuf, ".\n", 2))
+      return 1; /* error */
     msg_ctx = 0;
     while(!msg_ctx) {
       /* convert minor status code (underlying routine error) to text */
@@ -89,14 +87,16 @@ static int check_gss_err(struct Curl_easy *data,
                                     GSS_C_NULL_OID,
                                     &msg_ctx, &status_string);
       if(maj_stat == GSS_S_COMPLETE) {
-        if(sizeof(buf) > len + status_string.length)
-          strcpy(buf + len, (char *) status_string.value);
+        if(Curl_dyn_addn(&dbuf, status_string.value,
+                         status_string.length))
+          return 1; /* error */
         gss_release_buffer(&min_stat, &status_string);
         break;
       }
       gss_release_buffer(&min_stat, &status_string);
     }
-    failf(data, "GSS-API error: %s failed: %s", function, buf);
+    failf(data, "GSS-API error: %s failed: %s", function, Curl_dyn_ptr(&dbuf));
+    Curl_dyn_free(&dbuf);
     return 1;
   }