Skip to content

Commit

Permalink
fix parse: fix read user's dlen cause seg fault
Browse files Browse the repository at this point in the history
  • Loading branch information
ffashion committed Mar 1, 2024
1 parent 2a2a275 commit 5e53cb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/adb/xdbd_adb.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,17 @@ size_t xdbd_adb_read_adb_header(xdbd_adb_request_t *r) {

int xdbd_adb_parse_adb_header(xdbd_adb_request_t *r, xdbd_buf_t *b) {
ssize_t n;

xdbd_adb_packet_t *p;
n = xdbd_buf_size(b);

if (n < sizeof(xdbd_adb_header_t)) {
return XDBD_AGAIN;
}

xdbd_memcpy(&r->h, b->start, sizeof(xdbd_adb_header_t));

r->p = xdbd_pcalloc(r->temp_pool, sizeof(xdbd_adb_packet_t));
if (r->p == NULL) {
return XDBD_ERR;
}

r->p->payload = xdbd_create_buf(r->temp_pool, r->h.dlen);
if (r->p->payload == NULL) {
return XDBD_ERR;
}
p = r->p;

xdbd_memcpy(&r->h, b->start, sizeof(xdbd_adb_header_t));
p->header = r->h;

r->buffer->pos += sizeof(xdbd_adb_header_t);
return XDBD_OK;
Expand Down Expand Up @@ -123,8 +115,6 @@ size_t xdbd_adb_read_adb_payload(xdbd_adb_request_t *r) {
}

int xdbd_adb_parse_adb_payload(xdbd_adb_request_t *r, xdbd_buf_t *b) {
r->p->header = r->h;

xdbd_buf_append_buf(r->p->payload, r->pool, b);

xdbd_dump_adb_packet(r->pool, r->p);
Expand Down
15 changes: 15 additions & 0 deletions src/adb/xdbd_adb_request.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "adb.h"
#include "xdbd_adb.h"
#include "xdbd_buf.h"
#include "xdbd_pool.h"
#include <xdbd_adb_request.h>
#include <connection.h>

xdbd_adb_request_t *xdbd_adb_create_request(xdbd_connection_t *c) {
xdbd_adb_request_t *r;
xdbd_adb_packet_t *p;

r = xdbd_pcalloc(c->pool, sizeof(xdbd_adb_request_t));
if (r == NULL) {
Expand All @@ -17,5 +21,16 @@ xdbd_adb_request_t *xdbd_adb_create_request(xdbd_connection_t *c) {

r->coonection = c;

p = xdbd_pcalloc(r->pool, sizeof(xdbd_adb_packet_t));
if (p == NULL) {
return NULL;
}

p->payload = xdbd_create_buf(r->pool, ADB_MAX_PACKET_SIZE);
if (p->payload == NULL) {
return NULL;
}

r->p = p;
return r;
}
1 change: 1 addition & 0 deletions src/xdbd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "bfdev/log.h"
#include <xdbd_event.h>
#include <bfdev/list.h>
#include <bfdev.h>
Expand Down

0 comments on commit 5e53cb2

Please sign in to comment.