Browse Source

Handle NULL Pointer Dereference

jblanked 1 year ago
parent
commit
ea418e3ec8
3 changed files with 15 additions and 8 deletions
  1. 1 0
      assets/FlipperHTTP/README.md
  2. 7 4
      assets/FlipperHTTP/flipper_http.h
  3. 7 4
      flipper_http.h

+ 1 - 0
assets/FlipperHTTP/README.md

@@ -45,6 +45,7 @@ Star the repository (https://github.com/jblanked/WebCrawler-FlipperZero) and fol
 | `flipper_http_delete_request_with_headers`          | `bool`           | `const char *url`, `const char *headers`, `const char *payload`                                                 | Sends a DELETE request with custom headers and a payload to the specified URL.                        |
 | `flipper_http_save_received_data`                | `bool`           | `size_t bytes_received`, `const char line_buffer[]`                                                            | Saves the received data to the SD card, with the specified size and buffer.                        |
 
+`In C, fhttp.received_data holds the received data from HTTP requests. In JavaScript, the response is returned directly from the function.`
 
 ## Usage in `JavaScript` (flipper_http.js):
 | **Function Name**                      | **Return Value** | **Parameters**                                       | **Description**                                                                                      |

+ 7 - 4
assets/FlipperHTTP/flipper_http.h

@@ -349,6 +349,13 @@ void flipper_http_deinit()
         fhttp.received_data = NULL;
     }
 
+    // Free the last response
+    if (fhttp.last_response)
+    {
+        free(fhttp.last_response);
+        fhttp.last_response = NULL;
+    }
+
     FURI_LOG_I("FlipperHTTP", "UART deinitialized successfully.");
 }
 
@@ -967,7 +974,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_get = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }
@@ -977,7 +983,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_post = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }
@@ -987,7 +992,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_put = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }
@@ -997,7 +1001,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_delete = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }

+ 7 - 4
flipper_http.h

@@ -349,6 +349,13 @@ void flipper_http_deinit()
         fhttp.received_data = NULL;
     }
 
+    // Free the last response
+    if (fhttp.last_response)
+    {
+        free(fhttp.last_response);
+        fhttp.last_response = NULL;
+    }
+
     FURI_LOG_I("FlipperHTTP", "UART deinitialized successfully.");
 }
 
@@ -967,7 +974,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_get = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }
@@ -977,7 +983,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_post = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }
@@ -987,7 +992,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_put = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }
@@ -997,7 +1001,6 @@ void flipper_http_rx_callback(const char *line, void *context)
         fhttp.started_receiving_delete = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        free(fhttp.received_data);
         fhttp.received_data = NULL;
         return;
     }