thermosphere: gdb: fix parsing errors in vCont and hex decode

This commit is contained in:
TuxSH 2020-01-29 18:08:39 +00:00
parent b08c1e34b1
commit 5dd8e3c129
2 changed files with 15 additions and 8 deletions

View file

@ -365,7 +365,7 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
char *threadIdPart;
int threadId;
u32 curMask = 0;
char *cmdEnd;
const char *cmdEnd;
// It it always fine if we set the single-stepping range to 0,0 by default
// Because the fields we set are the shadow fields copied to the real fields after debug unpause
@ -380,13 +380,16 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
// Locate thread-id part, parse thread id
threadIdPart = strchr(cmd, ':');
if (threadIdPart != NULL) {
*threadIdPart++ = 0;
}
if (threadIdPart == NULL || strcmp(threadIdPart, "-1") == 0) {
// Default action...
threadId = -1;
curMask = ctx->attachedCoreList;
} else {
unsigned long id;
if(GDB_ParseHexIntegerList(&id, ctx->commandData + 1, 1, 0) == NULL) {
if(GDB_ParseHexIntegerList(&id, threadIdPart, 1, 0) == NULL) {
return GDB_ReplyErrno(ctx, EILSEQ);
} else if (id >= MAX_CORE + 1) {
return GDB_ReplyErrno(ctx, EINVAL);
@ -404,7 +407,7 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
case 'C': {
// Check the presence of the two-digit signature, even if we ignore it.
u8 sg;
if (GDB_DecodeHex(&sg, ctx->commandData, 1) != 1) {
if (GDB_DecodeHex(&sg, cmd + 1, 1) != 1) {
return GDB_ReplyErrno(ctx, EILSEQ);
}
stepCoreList |= cmd[0] == 'S' ? curMask : 0;
@ -428,7 +431,7 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
case 'r': {
// Range step
unsigned long tmp[2];
cmdEnd = GDB_ParseHexIntegerList(tmp, cmd, 2, 0);
cmdEnd = GDB_ParseHexIntegerList(tmp, cmd + 1, 2, 0);
if (cmdEnd == NULL) {
return GDB_ReplyErrno(ctx, EILSEQ);
}

View file

@ -50,13 +50,17 @@ static inline u32 GDB_DecodeHexDigit(char src, bool *ok)
size_t GDB_DecodeHex(void *dst, const char *src, size_t len) {
size_t i = 0;
bool ok = true;
u8 *dst8 = (u8 *)dst;
for (i = 0; i < len && ok && src[2 * i] != 0 && src[2 * i + 1] != 0; i++) {
dst8[i] = (GDB_DecodeHexDigit(src[2 * i], &ok) << 4) | GDB_DecodeHexDigit(src[2 * i + 1], &ok);
for (i = 0; i < len && src[2 * i] != 0 && src[2 * i + 1] != 0; i++) {
bool ok1, ok2;
dst8[i] = GDB_DecodeHexDigit(src[2 * i], &ok1) << 4;
dst8[i] |= GDB_DecodeHexDigit(src[2 * i + 1], &ok2);
if (!ok1 || !ok2) {
return i;
}
}
return (!ok) ? i - 1 : i;
return i;
}
size_t GDB_EscapeBinaryData(size_t *encodedCount, void *dst, const void *src, size_t len, size_t maxLen)