Fix a lot of incorrect 'garbage at end of packet' messages (#8080)

This commit is contained in:
Srimanta Barua 2017-08-01 15:10:33 +05:30 committed by radare
parent 579a043b87
commit 9f9192232a
2 changed files with 26 additions and 4 deletions

View File

@ -158,6 +158,7 @@ typedef struct libgdbr_t {
ssize_t send_max; // defines the maximal len for the given buffer
char *read_buff;
ssize_t read_max; // defines the maximal len for the given buffer
ssize_t read_len; // len of read_buff (if read_buff not fully consumed)
// is already handled (i.e. already send or ...)
RSocket *sock;

View File

@ -51,14 +51,23 @@ static int unpack(libgdbr_t *g, struct parse_ctx *ctx, int len) {
if (!--ctx->chksum_nibble) {
continue;
}
if (i != len - 1) {
eprintf ("%s: Garbage at end of packet: %s\n",
__func__, g->read_buff + i + 1);
}
if (ctx->sum != '#') {
eprintf ("%s: Invalid checksum\n", __func__);
return -1;
}
if (i != len - 1) {
if (g->read_buff[i + 1] == '$' ||
(g->read_buff[i + 1] == '+' && g->read_buff[i + 2] == '$')) {
// Packets clubbed together
g->read_len = len - i - 1;
memcpy (g->read_buff, g->read_buff + i + 1, g->read_len);
g->read_buff[g->read_len] = '\0';
return 0;
}
eprintf ("%s: Garbage at end of packet: %s\n",
__func__, g->read_buff + i + 1);
}
g->read_len = 0;
return 0;
}
ctx->sum += cur;
@ -138,6 +147,18 @@ int read_packet(libgdbr_t *g) {
return -1;
}
g->data_len = 0;
if (g->read_len > 0) {
if (unpack (g, &ctx, g->read_len) == 0) {
// TODO: Evaluate if partial packets are clubbed
g->data[g->data_len] = '\0';
if (g->server_debug) {
eprintf ("getpkt (\"%s\"); %s\n", g->data,
g->no_ack ? "[no ack sent]" : "[sending ack]");
}
return 0;
}
}
g->data_len = 0;
while (r_socket_ready (g->sock, 0, READ_TIMEOUT) > 0) {
int sz = r_socket_read (g->sock, (void *)g->read_buff, g->read_max - 1);
if (sz <= 0) {