瀏覽代碼

Bound GPIO names and handle handler allocation failure

SybexXx 2 天之前
父節點
當前提交
5268df5e2f
共有 1 個文件被更改,包括 8 次插入 和 4 次删除
  1. 8 4
      code/components/jomjol_controlGPIO/server_GPIO.cpp

+ 8 - 4
code/components/jomjol_controlGPIO/server_GPIO.cpp

@@ -406,7 +406,7 @@ bool GpioHandler::readConfig()
             bool httpEnabled = (toLower(splitted[5]) == "true");
             bool httpEnabled = (toLower(splitted[5]) == "true");
             char gpioName[100];
             char gpioName[100];
             if (splitted.size() >= 7) {
             if (splitted.size() >= 7) {
-                strcpy(gpioName, trim(splitted[6]).c_str());
+                strlcpy(gpioName, trim(splitted[6]).c_str(), sizeof(gpioName));
             } else {
             } else {
                 sprintf(gpioName, "GPIO%d", gpioNr);
                 sprintf(gpioName, "GPIO%d", gpioNr);
             }
             }
@@ -724,10 +724,14 @@ gpio_int_type_t GpioHandler::resolveIntType(std::string input)
 
 
 static GpioHandler *gpioHandler = NULL;
 static GpioHandler *gpioHandler = NULL;
 
 
-void gpio_handler_create(httpd_handle_t server) 
+void gpio_handler_create(httpd_handle_t server)
 {
 {
-    if (gpioHandler == NULL)
-        gpioHandler = new GpioHandler(CONFIG_FILE, server);
+    if (gpioHandler == NULL) {
+        gpioHandler = new (std::nothrow) GpioHandler(CONFIG_FILE, server);
+        if (gpioHandler == NULL) {
+            LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Unable to allocate GPIO handler");
+        }
+    }
 }
 }
 
 
 void gpio_handler_init() 
 void gpio_handler_init()