diff --git a/thermosphere/src/gdb/debug.c b/thermosphere/src/gdb/debug.c index f35155b0a..1be2229c8 100644 --- a/thermosphere/src/gdb/debug.c +++ b/thermosphere/src/gdb/debug.c @@ -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); } diff --git a/thermosphere/src/gdb/net.c b/thermosphere/src/gdb/net.c index 2963df197..5553c08ad 100644 --- a/thermosphere/src/gdb/net.c +++ b/thermosphere/src/gdb/net.c @@ -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)