1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-19 08:52:25 +00:00

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 cbf3b305ca
commit 9ef2532b9d
2 changed files with 15 additions and 8 deletions

View file

@ -365,7 +365,7 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
char *threadIdPart; char *threadIdPart;
int threadId; int threadId;
u32 curMask = 0; u32 curMask = 0;
char *cmdEnd; const char *cmdEnd;
// It it always fine if we set the single-stepping range to 0,0 by default // 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 // 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 // Locate thread-id part, parse thread id
threadIdPart = strchr(cmd, ':'); threadIdPart = strchr(cmd, ':');
if (threadIdPart != NULL) {
*threadIdPart++ = 0;
}
if (threadIdPart == NULL || strcmp(threadIdPart, "-1") == 0) { if (threadIdPart == NULL || strcmp(threadIdPart, "-1") == 0) {
// Default action... // Default action...
threadId = -1; threadId = -1;
curMask = ctx->attachedCoreList; curMask = ctx->attachedCoreList;
} else { } else {
unsigned long id; 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); return GDB_ReplyErrno(ctx, EILSEQ);
} else if (id >= MAX_CORE + 1) { } else if (id >= MAX_CORE + 1) {
return GDB_ReplyErrno(ctx, EINVAL); return GDB_ReplyErrno(ctx, EINVAL);
@ -404,7 +407,7 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
case 'C': { case 'C': {
// Check the presence of the two-digit signature, even if we ignore it. // Check the presence of the two-digit signature, even if we ignore it.
u8 sg; u8 sg;
if (GDB_DecodeHex(&sg, ctx->commandData, 1) != 1) { if (GDB_DecodeHex(&sg, cmd + 1, 1) != 1) {
return GDB_ReplyErrno(ctx, EILSEQ); return GDB_ReplyErrno(ctx, EILSEQ);
} }
stepCoreList |= cmd[0] == 'S' ? curMask : 0; stepCoreList |= cmd[0] == 'S' ? curMask : 0;
@ -428,7 +431,7 @@ GDB_DECLARE_VERBOSE_HANDLER(Continue)
case 'r': { case 'r': {
// Range step // Range step
unsigned long tmp[2]; unsigned long tmp[2];
cmdEnd = GDB_ParseHexIntegerList(tmp, cmd, 2, 0); cmdEnd = GDB_ParseHexIntegerList(tmp, cmd + 1, 2, 0);
if (cmdEnd == NULL) { if (cmdEnd == NULL) {
return GDB_ReplyErrno(ctx, EILSEQ); 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 GDB_DecodeHex(void *dst, const char *src, size_t len) {
size_t i = 0; size_t i = 0;
bool ok = true;
u8 *dst8 = (u8 *)dst; u8 *dst8 = (u8 *)dst;
for (i = 0; i < len && ok && src[2 * i] != 0 && src[2 * i + 1] != 0; i++) { for (i = 0; i < len && 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); 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) size_t GDB_EscapeBinaryData(size_t *encodedCount, void *dst, const void *src, size_t len, size_t maxLen)