Skip to content

Commit c5f6de2

Browse files
validate zero size before calling address_valid_write
1 parent 3a27639 commit c5f6de2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/basic/file_io.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ void readbinary_statement(struct basic_ctx* ctx)
283283
int64_t buffer = expr(ctx);
284284
accept_or_return(COMMA, ctx);
285285
int64_t size = expr(ctx);
286-
if (!address_valid_write(buffer, size)) {
286+
if (size && !address_valid_write(buffer, size)) {
287287
tokenizer_error_printf(ctx, "Invalid address: %016lx", (uint64_t)buffer);
288288
return;
289289
}
290-
if (_read(fd, buffer, size) == -1) {
290+
if (size && _read(fd, buffer, size) == -1) {
291291
tokenizer_error_printf(ctx, "Error reading from file: %s", fs_strerror(fs_get_error()));
292292
}
293293
accept_or_return(NEWLINE, ctx);
@@ -301,11 +301,11 @@ void writebinary_statement(struct basic_ctx* ctx)
301301
int64_t buffer = expr(ctx);
302302
accept_or_return(COMMA, ctx);
303303
int64_t size = expr(ctx);
304-
if (!address_valid_read(buffer, size)) {
304+
if (size && !address_valid_read(buffer, size)) {
305305
tokenizer_error_printf(ctx, "Invalid address: %016lx", (uint64_t)buffer);
306306
return;
307307
}
308-
if (_write(fd, buffer, size) == -1) {
308+
if (size && _write(fd, buffer, size) == -1) {
309309
tokenizer_error_printf(ctx, "Error writing to file: %s", fs_strerror(fs_get_error()));
310310
}
311311
accept_or_return(NEWLINE, ctx);

src/basic/sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void sockbinread_statement(struct basic_ctx* ctx)
106106
int64_t address = expr(ctx);
107107
accept_or_return(COMMA, ctx);
108108
int64_t length = expr(ctx);
109-
if (!address_valid_write(address, length)) {
109+
if (length && !address_valid_write(address, length)) {
110110
tokenizer_error_printf(ctx, "Invalid address: %016lx", (uint64_t)address);
111111
return;
112112
}
@@ -332,7 +332,7 @@ void sockbinwrite_statement(struct basic_ctx* ctx) {
332332
uint64_t buffer_pointer = expr(ctx);
333333
accept_or_return(COMMA, ctx);
334334
int length = expr(ctx);
335-
if (!address_valid_read(buffer_pointer, length)) {
335+
if (length && !address_valid_read(buffer_pointer, length)) {
336336
tokenizer_error_printf(ctx, "Invalid address: %016lx", buffer_pointer);
337337
return;
338338
}

0 commit comments

Comments
 (0)