This commit is contained in:
iceman1001 2020-01-05 21:45:29 +01:00
commit eb4573b06c
3 changed files with 21 additions and 11 deletions

View file

@ -10,9 +10,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "proxmark3.h" #include "proxmark3.h"
#include <limits.h>
#include <stdio.h> // for Mingw readline
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> // for Mingw readline
#include <limits.h>
#include <unistd.h> #include <unistd.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
@ -27,7 +28,6 @@
#include "fileutils.h" #include "fileutils.h"
#include "flash.h" #include "flash.h"
static void showBanner(void) { static void showBanner(void) {
g_printAndLog = PRINTANDLOG_PRINT; g_printAndLog = PRINTANDLOG_PRINT;
@ -169,13 +169,16 @@ check_script:
// remove linebreaks // remove linebreaks
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf)); 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; printprompt = true;
} }
} else { } else {
// If there is a script command // If there is a script command
if (execCommand) { if (execCommand) {
if ((cmd = strmcopy(script_cmd)) != NULL)
cmd = strdup(script_cmd);
if (cmd != NULL)
printprompt = true; printprompt = true;
uint16_t len = strlen(script_cmd) + 1; uint16_t len = strlen(script_cmd) + 1;
@ -203,7 +206,8 @@ check_script:
// remove linebreaks // remove linebreaks
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf)); 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; printprompt = true;
} else { } else {

View file

@ -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 *strdup(const char *src) {
char *dest = (char *) calloc(len, sizeof(uint8_t)); 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) { if (dest != NULL) {
strncat(dest, src, len); memcpy(dest, src, len);
dest[len] = '\0';
} }
return dest; return dest;
} }

View file

@ -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 clean_ascii(unsigned char *buf, size_t len);
void strcleanrn(char *buf, size_t len); void strcleanrn(char *buf, size_t len);
void strcreplace(char *buf, size_t len, char from, char to); 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); int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
#endif #endif