Fixing segfault

This commit is contained in:
Philippe Teuwen 2019-05-18 18:41:24 +02:00
commit e6d64df6d0

View file

@ -52,7 +52,7 @@ static int usage_hw_connect(void) {
PrintAndLogEx(NORMAL, "Connects to a Proxmark3 device via specified serial port"); PrintAndLogEx(NORMAL, "Connects to a Proxmark3 device via specified serial port");
PrintAndLogEx(NORMAL, "Baudrate here is only for physical UART or UART-BT, " _YELLOW_("not")"for USB-CDC or blue shark add-on"); PrintAndLogEx(NORMAL, "Baudrate here is only for physical UART or UART-BT, " _YELLOW_("not")"for USB-CDC or blue shark add-on");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hw connect [h] p <port> b <baudrate>"); PrintAndLogEx(NORMAL, "Usage: hw connect [h] [p <port>] [b <baudrate>]");
PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help"); PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " p <port> Serial port to connect to, else retry the last used one"); PrintAndLogEx(NORMAL, " p <port> Serial port to connect to, else retry the last used one");
@ -501,23 +501,18 @@ static int CmdConnect(const char *Cmd) {
char *port= NULL; char *port= NULL;
uint32_t baudrate = USART_BAUD_RATE; uint32_t baudrate = USART_BAUD_RATE;
uint8_t cmdp = 0; uint8_t cmdp = 0;
int sl;
while (param_getchar(Cmd, cmdp) != 0x00) { while (param_getchar(Cmd, cmdp) != 0x00) {
switch (tolower(param_getchar(Cmd, cmdp))) { switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h': case 'h':
return usage_hw_connect(); return usage_hw_connect();
case 'p': case 'p': {
sl = param_getlength(Cmd, cmdp + 1); int bg, en;
sl += 1; if (param_getptr(Cmd, &bg, &en, cmdp + 1)) break;
port = (char *)calloc(sl, sizeof(uint8_t)); port = (char *)Cmd + bg;
if ( port == NULL ) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return 1;
}
param_getstr(Cmd, cmdp + 1, port, sl);
cmdp += 2; cmdp += 2;
break; break;
}
case 'b': case 'b':
baudrate = param_get32ex(Cmd, cmdp + 1, USART_BAUD_RATE, 10); baudrate = param_get32ex(Cmd, cmdp + 1, USART_BAUD_RATE, 10);
cmdp += 2; cmdp += 2;
@ -553,7 +548,6 @@ static int CmdConnect(const char *Cmd) {
PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark3\n"); PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark3\n");
CloseProxmark(); CloseProxmark();
} }
free(port);
return PM3_SUCCESS; return PM3_SUCCESS;
} }