Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1commit ebcdbd9b3c9d437780aee4d6af76bbd2ab32ea06 2Author: LeRoyce Pearson <contact@leroycepearson.dev> 3Date: 2022-07-17 16:01:22 -0600 4 5 Read dynstr starting at rpath offset 6 7 Since we know the offset, we may as well read starting there. Still expects 8 rpath to fit in 4096 bytes; that might be worth fixing in the future. 9 10 Fixes issue #12112 11 12diff --git a/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig 13index af41fc790579..ad0b6d5ce1e1 100644 14--- a/lib/std/zig/system/NativeTargetInfo.zig 15+++ b/lib/std/zig/system/NativeTargetInfo.zig 16@@ -652,14 +652,19 @@ pub fn abiAndDynamicLinkerFromFile( 17 } else null; 18 19 if (dynstr) |ds| { 20- const strtab_len = std.math.min(ds.size, strtab_buf.len); 21- const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, strtab_len); 22- const strtab = strtab_buf[0..strtab_read_len]; 23 // TODO this pointer cast should not be necessary 24 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) { 25 error.Overflow => return error.InvalidElfFile, 26 }; 27- const rpath_list = mem.sliceTo(std.meta.assumeSentinel(strtab[rpoff_usize..].ptr, 0), 0); 28+ if (rpoff_usize > ds.size) return error.InvalidElfFile; 29+ const rpoff_file = ds.offset + rpoff_usize; 30+ const rp_max_size = ds.size - rpoff_usize; 31+ 32+ const strtab_len = std.math.min(rp_max_size, strtab_buf.len); 33+ const strtab_read_len = try preadMin(file, &strtab_buf, rpoff_file, strtab_len); 34+ const strtab = strtab_buf[0..strtab_read_len]; 35+ 36+ const rpath_list = mem.sliceTo(std.meta.assumeSentinel(strtab.ptr, 0), 0); 37 var it = mem.tokenize(u8, rpath_list, ":"); 38 while (it.next()) |rpath| { 39 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {