mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-10-06 16:27:45 +00:00
fix more stabilty issues with NULL checks and leaving values after REALLOC
This commit is contained in:
+12
-12
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user