Imported Upstream version 7.44.0
[platform/upstream/curl.git] / lib / smb.c
index e66427b..d461a71 100644 (file)
--- a/lib/smb.c
+++ b/lib/smb.c
 #include "transfer.h"
 #include "vtls/vtls.h"
 #include "curl_ntlm_core.h"
-#include "curl_memory.h"
 #include "escape.h"
 #include "curl_endian.h"
 
-/* The last #include file should be: */
+/* The last #include files should be: */
+#include "curl_memory.h"
 #include "memdebug.h"
 
 /* Local API functions */
@@ -783,9 +783,15 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
     off = Curl_read16_le(((unsigned char *) msg) +
                          sizeof(struct smb_header) + 13);
     if(len > 0) {
-      result = Curl_client_write(conn, CLIENTWRITE_BODY,
-                                 (char *)msg + off + sizeof(unsigned int),
-                                 len);
+      struct smb_conn *smbc = &conn->proto.smbc;
+      if(off + sizeof(unsigned int) + len > smbc->got) {
+        failf(conn->data, "Invalid input packet");
+        result = CURLE_RECV_ERROR;
+      }
+      else
+        result = Curl_client_write(conn, CLIENTWRITE_BODY,
+                                   (char *)msg + off + sizeof(unsigned int),
+                                   len);
       if(result) {
         req->result = result;
         next_state = SMB_CLOSE;
@@ -935,7 +941,7 @@ static CURLcode smb_parse_url_path(struct connectdata *conn)
   /* Parse the path for the share */
   req->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path);
   if(!req->share) {
-    Curl_safefree(path);
+    free(path);
 
     return CURLE_OUT_OF_MEMORY;
   }
@@ -946,7 +952,7 @@ static CURLcode smb_parse_url_path(struct connectdata *conn)
 
   /* The share must be present */
   if(!slash) {
-    Curl_safefree(path);
+    free(path);
 
     return CURLE_URL_MALFORMAT;
   }
@@ -960,7 +966,7 @@ static CURLcode smb_parse_url_path(struct connectdata *conn)
       *slash = '\\';
   }
 
-  Curl_safefree(path);
+  free(path);
 
   return CURLE_OK;
 }