diff --git a/client/proxmark3.c b/client/proxmark3.c index 5d0b47fb3..76048952f 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -10,9 +10,10 @@ //----------------------------------------------------------------------------- #include "proxmark3.h" -#include -#include // for Mingw readline + #include +#include // for Mingw readline +#include #include #include #include @@ -27,7 +28,6 @@ #include "fileutils.h" #include "flash.h" - static void showBanner(void) { g_printAndLog = PRINTANDLOG_PRINT; @@ -169,13 +169,16 @@ check_script: // remove linebreaks strcleanrn(script_cmd_buf, sizeof(script_cmd_buf)); - if ((cmd = strmcopy(script_cmd_buf)) != NULL) + cmd = strdup(script_cmd_buf); + if (cmd != NULL) printprompt = true; } } else { // If there is a script command if (execCommand) { - if ((cmd = strmcopy(script_cmd)) != NULL) + + cmd = strdup(script_cmd); + if (cmd != NULL) printprompt = true; uint16_t len = strlen(script_cmd) + 1; @@ -203,7 +206,8 @@ check_script: // remove linebreaks strcleanrn(script_cmd_buf, sizeof(script_cmd_buf)); - if ((cmd = strmcopy(script_cmd_buf)) != NULL) + cmd = strdup(script_cmd_buf); + if (cmd != NULL) printprompt = true; } else { diff --git a/client/util.c b/client/util.c index e5446313d..41ee8f0d8 100644 --- a/client/util.c +++ b/client/util.c @@ -918,11 +918,16 @@ void strcreplace(char *buf, size_t len, char from, char to) { } } -char *strmcopy(const char *src) { - int len = strlen(src) + 1; - char *dest = (char *) calloc(len, sizeof(uint8_t)); + +char *strdup(const char *src) { + return strndup(src, strlen(src)); +} +char *strndup(const char *src, size_t len) { + + char *dest = (char *) calloc(len + 1, sizeof(uint8_t)); if (dest != NULL) { - strncat(dest, src, len); + memcpy(dest, src, len); + dest[len] = '\0'; } return dest; } diff --git a/client/util.h b/client/util.h index 043f08e5d..b5a4be4a6 100644 --- a/client/util.h +++ b/client/util.h @@ -99,6 +99,7 @@ bool str_endswith(const char *s, const char *suffix); // check for suffix in void clean_ascii(unsigned char *buf, size_t len); void strcleanrn(char *buf, size_t len); void strcreplace(char *buf, size_t len, char from, char to); -char *strmcopy(const char *src); +char *strdup(const char *src); +char *strndup(const char *src, size_t len); int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str); #endif