trace load: keep the current trace when loading a file fails
The trace buffer was cleared before the load, so a missing or empty file lost the trace already loaded. Loading straight into gs_trace also left it dangling when loadFile_safe() freed it on a short read, to be freed again by the next clear or load. Load into a local buffer and swap it in on success. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2c60f882f8
commit
00a759b0c7
1 file changed
+5
-3
@@ -1582,14 +1582,16 @@ static int CmdTraceLoad(const char *Cmd) {
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
ClearTraceBuffer(); // maybe better to not clobber this until we have successful load?
|
||||
|
||||
// keep the current trace until the new one has loaded
|
||||
uint8_t *trace = NULL;
|
||||
size_t len = 0;
|
||||
if (loadFile_safe(filename, ".trace", (void **)&gs_trace, &len) != PM3_SUCCESS) {
|
||||
if (loadFile_safe(filename, ".trace", (void **)&trace, &len) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(FAILED, "Could not open file " _YELLOW_("%s"), filename);
|
||||
return PM3_EIO;
|
||||
}
|
||||
|
||||
ClearTraceBuffer();
|
||||
gs_trace = trace;
|
||||
gs_traceLen = (uint32_t)len;
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = " _YELLOW_("%u") " bytes)", gs_traceLen);
|
||||
|
||||
Reference in new issue
Block a user