]> granicus.if.org Git - curl/commitdiff
tftp: make sure error is zero terminated before printfing it
authorDaniel Stenberg <daniel@haxx.se>
Tue, 22 May 2018 08:10:39 +0000 (10:10 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 22 May 2018 08:10:39 +0000 (10:10 +0200)
lib/tftp.c

index b32960f82b8b9d2aa2ac29062bd51eda4d6bd15c..d57af6a7a13976de3da4cc7d0392d99dd848d449 100644 (file)
@@ -1148,8 +1148,11 @@ static CURLcode tftp_receive_packet(struct connectdata *conn)
     case TFTP_EVENT_ERROR:
     {
       unsigned short error = getrpacketblock(&state->rpacket);
+      char *str = (char *)state->rpacket.data + 4;
+      size_t strn = state->rbytes - 4;
       state->error = (tftp_error_t)error;
-      infof(data, "%s\n", (const char *)state->rpacket.data + 4);
+      if(Curl_strnlen(str, strn) < strn)
+        infof(data, "TFTP error: %s\n", str);
       break;
     }
     case TFTP_EVENT_ACK: