Skip to content

Commit 370ba44

Browse files
authored
os: fix buffer overflow in os.get_raw_line under Windows (#23816)
1 parent a1f7213 commit 370ba44

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

vlib/os/os.c.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ pub fn get_raw_line() string {
504504
$if windows {
505505
unsafe {
506506
max_line_chars := 256
507-
buf := malloc_noscan(max_line_chars * 2)
507+
mut old_size := max_line_chars * 2
508+
mut buf := malloc_noscan(old_size)
508509
h_input := C.GetStdHandle(C.STD_INPUT_HANDLE)
509510
mut bytes_read := u32(0)
510511
if is_atty(0) > 0 {
@@ -530,6 +531,11 @@ pub fn get_raw_line() string {
530531
break
531532
}
532533
offset++
534+
if offset >= old_size {
535+
new_size := old_size + max_line_chars * 2
536+
buf = realloc_data(buf, old_size, new_size)
537+
old_size = new_size
538+
}
533539
}
534540
return buf.vstring_with_len(offset)
535541
}

0 commit comments

Comments
 (0)