Skip to content

Commit e0b1977

Browse files
yossizapradare
authored andcommitted
Fixed overflow that broke remote debugger reopening ##debug (#15525)
opt->sz is initialized with r_buf_size at r_bin_open_io using an io buffer if r_bin_open_io can't open a file buffer. Since the debuggers returned unsigned values to opt->sz which is signed, opt->sz would overflow and contain a negative value, causing r_bin_open_buf to fail. Went ahead and modified CUR_END values for all debuggers even though this should only affect remote debuggers. ST64_MAX should be enough.
1 parent e132818 commit e0b1977

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

libr/io/p/io_gdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
156156
io->off += offset;
157157
break;
158158
case R_IO_SEEK_END:
159-
io->off = UT64_MAX;
159+
io->off = ST64_MAX;
160160
}
161161
return io->off;
162162
}

libr/io/p/io_mach.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,14 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
444444

445445
static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
446446
switch (whence) {
447-
case 0: // abs
447+
case R_IO_SEEK_SET:
448448
io->off = offset;
449449
break;
450-
case 1: // cur
451-
io->off += (int)offset;
452-
break;
453-
case 2: // end
454-
io->off = UT64_MAX;
450+
case R_IO_SEEK_CUR:
451+
io->off += offset;
455452
break;
453+
case R_IO_SEEK_END:
454+
io->off = ST64_MAX;
456455
}
457456
return io->off;
458457
}

libr/io/p/io_ptrace.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,14 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
251251

252252
static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
253253
switch (whence) {
254-
case 0: // abs
254+
case R_IO_SEEK_SET:
255255
io->off = offset;
256256
break;
257-
case 1: // cur
258-
io->off += (int)offset;
259-
break;
260-
case 2: // end
261-
io->off = UT64_MAX;
257+
case R_IO_SEEK_CUR:
258+
io->off += offset;
262259
break;
260+
case R_IO_SEEK_END:
261+
io->off = ST64_MAX;
263262
}
264263
return io->off;
265264
}

libr/io/p/io_w32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int w32__close(RIODesc *fd) {
3636
// TODO: handle filesize and so on
3737
static ut64 w32__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
3838
SetFilePointer (RIOW32_HANDLE (fd), offset, 0, !whence?FILE_BEGIN:whence==1?FILE_CURRENT:FILE_END);
39-
return (!whence)?offset:whence==1?io->off+offset:UT64_MAX;
39+
return (!whence)?offset:whence==1?io->off+offset:ST64_MAX;
4040
}
4141

4242
static bool w32__plugin_open(RIO *io, const char *pathname, bool many) {

libr/io/p/io_windbg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
6666
case R_IO_SEEK_CUR:
6767
return io->off + offset;
6868
case R_IO_SEEK_END:
69-
return UT64_MAX;
69+
return ST64_MAX;
7070
default:
7171
return offset;
7272
}

libr/io/p/io_winedbg.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,14 @@ static int __close(RIODesc *fd) {
141141

142142
static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
143143
switch (whence) {
144-
case SEEK_SET:
144+
case R_IO_SEEK_SET:
145145
io->off = offset;
146-
return offset;
147-
case SEEK_CUR:
148-
return io->off + offset;
149-
case SEEK_END:
150-
return UT64_MAX;
146+
break;
147+
case R_IO_SEEK_CUR:
148+
io->off += offset;
149+
break;
150+
case R_IO_SEEK_END:
151+
io->off = ST64_MAX;
151152
}
152153
io->off = offset;
153154
return offset;

0 commit comments

Comments
 (0)