fix more stabilty issues with NULL checks and leaving values after REALLOC

This commit is contained in:
iceman1001
2026-09-16 13:58:20 +02:00
parent 5318069ccf
commit f76ae2b3f2
2 changed files with 18 additions and 18 deletions
+12 -12
View File
@@ -305,24 +305,24 @@ static int CmdMqttSend(const char *Cmd) {
}
if (alen == 0) {
if (strlen(g_session.mqtt_server)) {
strcpy(addr, g_session.mqtt_server);
if ((g_session.mqtt_server != NULL) && (strcmp(g_session.mqtt_server, "") != 0)) {
snprintf(addr, sizeof(addr), "%s", g_session.mqtt_server);
} else {
strcpy(addr, "mqtt.proxdump.com");
}
}
if (plen == 0) {
if (strlen(g_session.mqtt_port)) {
strcpy(port, g_session.mqtt_port);
if ((g_session.mqtt_port != NULL) && (strcmp(g_session.mqtt_port, "") != 0)) {
snprintf(port, sizeof(port), "%s", g_session.mqtt_port);
} else {
strcpy(port, "1883");
}
}
if (tlen == 0) {
if (strlen(g_session.mqtt_topic)) {
strcpy(topic, g_session.mqtt_topic);
if ((g_session.mqtt_topic != NULL) && (strcmp(g_session.mqtt_topic, "") != 0)) {
snprintf(topic, sizeof(topic), "%s", g_session.mqtt_topic);
} else {
strcpy(topic, "proxdump");
}
@@ -382,24 +382,24 @@ static int CmdMqttReceive(const char *Cmd) {
}
if (alen == 0) {
if (strlen(g_session.mqtt_server)) {
strcpy(addr, g_session.mqtt_server);
if ((g_session.mqtt_server != NULL) && (strcmp(g_session.mqtt_server, "") != 0)) {
snprintf(addr, sizeof(addr), "%s", g_session.mqtt_server);
} else {
strcpy(addr, "proxdump.com");
}
}
if (plen == 0) {
if (strlen(g_session.mqtt_port)) {
strcpy(port, g_session.mqtt_port);
if ((g_session.mqtt_port != NULL) && (strcmp(g_session.mqtt_port, "") != 0)) {
snprintf(port, sizeof(port), "%s", g_session.mqtt_port);
} else {
strcpy(port, "1883");
}
}
if (tlen == 0) {
if (strlen(g_session.mqtt_topic)) {
strcpy(topic, g_session.mqtt_topic);
if ((g_session.mqtt_topic != NULL) && (strcmp(g_session.mqtt_topic, "") != 0)) {
snprintf(topic, sizeof(topic), "%s", g_session.mqtt_topic);
} else {
strcpy(topic, "proxdump");
}
+6 -6
View File
@@ -61,9 +61,9 @@ static bool setDefaultMqttServer(const char *srv) {
char *tmp = (char *)realloc(g_session.mqtt_server, strlen(srv) + 1);
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");
free(g_session.mqtt_server);
g_session.mqtt_server = NULL;
return false;
}
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);
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");
free(g_session.mqtt_port);
g_session.mqtt_port = NULL;
return false;
}
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);
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");
free(g_session.mqtt_topic);
g_session.mqtt_topic = NULL;
return false;
}
g_session.mqtt_topic = tmp;