fix more stabilty issues with NULL checks and leaving values after REALLOC
This commit is contained in:
1 parent
5318069ccf
commit
f76ae2b3f2
2 files changed
+18
-18
No files matched your search
+12
-12
@@ -305,24 +305,24 @@ static int CmdMqttSend(const char *Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (alen == 0) {
|
if (alen == 0) {
|
||||||
if (strlen(g_session.mqtt_server)) {
|
if ((g_session.mqtt_server != NULL) && (strcmp(g_session.mqtt_server, "") != 0)) {
|
||||||
strcpy(addr, g_session.mqtt_server);
|
snprintf(addr, sizeof(addr), "%s", g_session.mqtt_server);
|
||||||
} else {
|
} else {
|
||||||
strcpy(addr, "mqtt.proxdump.com");
|
strcpy(addr, "mqtt.proxdump.com");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plen == 0) {
|
if (plen == 0) {
|
||||||
if (strlen(g_session.mqtt_port)) {
|
if ((g_session.mqtt_port != NULL) && (strcmp(g_session.mqtt_port, "") != 0)) {
|
||||||
strcpy(port, g_session.mqtt_port);
|
snprintf(port, sizeof(port), "%s", g_session.mqtt_port);
|
||||||
} else {
|
} else {
|
||||||
strcpy(port, "1883");
|
strcpy(port, "1883");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tlen == 0) {
|
if (tlen == 0) {
|
||||||
if (strlen(g_session.mqtt_topic)) {
|
if ((g_session.mqtt_topic != NULL) && (strcmp(g_session.mqtt_topic, "") != 0)) {
|
||||||
strcpy(topic, g_session.mqtt_topic);
|
snprintf(topic, sizeof(topic), "%s", g_session.mqtt_topic);
|
||||||
} else {
|
} else {
|
||||||
strcpy(topic, "proxdump");
|
strcpy(topic, "proxdump");
|
||||||
}
|
}
|
||||||
@@ -382,24 +382,24 @@ static int CmdMqttReceive(const char *Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (alen == 0) {
|
if (alen == 0) {
|
||||||
if (strlen(g_session.mqtt_server)) {
|
if ((g_session.mqtt_server != NULL) && (strcmp(g_session.mqtt_server, "") != 0)) {
|
||||||
strcpy(addr, g_session.mqtt_server);
|
snprintf(addr, sizeof(addr), "%s", g_session.mqtt_server);
|
||||||
} else {
|
} else {
|
||||||
strcpy(addr, "proxdump.com");
|
strcpy(addr, "proxdump.com");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plen == 0) {
|
if (plen == 0) {
|
||||||
if (strlen(g_session.mqtt_port)) {
|
if ((g_session.mqtt_port != NULL) && (strcmp(g_session.mqtt_port, "") != 0)) {
|
||||||
strcpy(port, g_session.mqtt_port);
|
snprintf(port, sizeof(port), "%s", g_session.mqtt_port);
|
||||||
} else {
|
} else {
|
||||||
strcpy(port, "1883");
|
strcpy(port, "1883");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tlen == 0) {
|
if (tlen == 0) {
|
||||||
if (strlen(g_session.mqtt_topic)) {
|
if ((g_session.mqtt_topic != NULL) && (strcmp(g_session.mqtt_topic, "") != 0)) {
|
||||||
strcpy(topic, g_session.mqtt_topic);
|
snprintf(topic, sizeof(topic), "%s", g_session.mqtt_topic);
|
||||||
} else {
|
} else {
|
||||||
strcpy(topic, "proxdump");
|
strcpy(topic, "proxdump");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ static bool setDefaultMqttServer(const char *srv) {
|
|||||||
|
|
||||||
char *tmp = (char *)realloc(g_session.mqtt_server, strlen(srv) + 1);
|
char *tmp = (char *)realloc(g_session.mqtt_server, strlen(srv) + 1);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
|
// keep the old value. realloc leaves it valid on failure, and dropping it
|
||||||
|
// would hand every later reader a NULL
|
||||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
free(g_session.mqtt_server);
|
|
||||||
g_session.mqtt_server = NULL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_session.mqtt_server = tmp;
|
g_session.mqtt_server = tmp;
|
||||||
@@ -84,9 +84,9 @@ static bool setDefaultMqttPort(const char *port) {
|
|||||||
|
|
||||||
char *tmp = (char *)realloc(g_session.mqtt_port, strlen(port) + 1);
|
char *tmp = (char *)realloc(g_session.mqtt_port, strlen(port) + 1);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
|
// keep the old value. realloc leaves it valid on failure, and dropping it
|
||||||
|
// would hand every later reader a NULL
|
||||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
free(g_session.mqtt_port);
|
|
||||||
g_session.mqtt_port = NULL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_session.mqtt_port = tmp;
|
g_session.mqtt_port = tmp;
|
||||||
@@ -107,9 +107,9 @@ static bool setDefaultMqttTopic(const char *topic) {
|
|||||||
|
|
||||||
char *tmp = (char *)realloc(g_session.mqtt_topic, strlen(topic) + 1);
|
char *tmp = (char *)realloc(g_session.mqtt_topic, strlen(topic) + 1);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
|
// keep the old value. realloc leaves it valid on failure, and dropping it
|
||||||
|
// would hand every later reader a NULL
|
||||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
free(g_session.mqtt_topic);
|
|
||||||
g_session.mqtt_topic = NULL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_session.mqtt_topic = tmp;
|
g_session.mqtt_topic = tmp;
|
||||||
|
|||||||
Reference in new issue
Block a user