[PATCH] telnet: only accept option arguments in ascii
authorDaniel Stenberg <daniel@haxx.se>
Mon, 6 Mar 2023 11:07:33 +0000 (12:07 +0100)
committerCarlos Henrique Lima Melara <charlesmelara@riseup.net>
Fri, 15 Sep 2023 17:01:23 +0000 (18:01 +0100)
To avoid embedded telnet negotiation commands etc.

Reported-by: Harry Sintonen
Closes #10728

Backported to Debian by Samuel Henrique <samueloph@debian.org>

Gbp-Pq: Name CVE-2023-27533.patch

lib/telnet.c

index a964bfdcde55db39e8739ddcf17341dc746fe16d..18e739bb65d778168fb39e64c3ec6c12ecbc97de 100644 (file)
@@ -770,6 +770,17 @@ static void printsub(struct Curl_easy *data,
   }
 }
 
+static bool str_is_nonascii(const char *str)
+{
+  size_t len = strlen(str);
+  while(len--) {
+    if(*str & 0x80)
+      return TRUE;
+    str++;
+  }
+  return FALSE;
+}
+
 static CURLcode check_telnet_options(struct Curl_easy *data)
 {
   struct curl_slist *head;
@@ -784,6 +795,8 @@ static CURLcode check_telnet_options(struct Curl_easy *data)
   /* Add the user name as an environment variable if it
      was given on the command line */
   if(data->state.aptr.user) {
+    if(str_is_nonascii(data->conn->user))
+      return CURLE_BAD_FUNCTION_ARGUMENT;
     msnprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user);
     beg = curl_slist_append(tn->telnet_vars, option_arg);
     if(!beg) {
@@ -798,7 +811,8 @@ static CURLcode check_telnet_options(struct Curl_easy *data)
   for(head = data->set.telnet_options; head; head = head->next) {
     if(sscanf(head->data, "%127[^= ]%*[ =]%255s",
               option_keyword, option_arg) == 2) {
-
+      if(str_is_nonascii(option_arg))
+        continue;
       /* Terminal type */
       if(strcasecompare(option_keyword, "TTYPE")) {
         strncpy(tn->subopt_ttype, option_arg, 31);