aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-06-20 21:17:32 -0700
committerGravatar GitHub <noreply@github.com> 2023-06-20 21:17:32 -0700
commitf81c7f10f68097e1dd3a7c65e82af63d65d678f9 (patch)
tree02d3d3f40b8e19a6800117a4ae2b695d87dfc7a1 /src
parentb9c950bfb7a15d0801216d8985ed8bb73f726528 (diff)
downloadbun-f81c7f10f68097e1dd3a7c65e82af63d65d678f9.tar.gz
bun-f81c7f10f68097e1dd3a7c65e82af63d65d678f9.tar.zst
bun-f81c7f10f68097e1dd3a7c65e82af63d65d678f9.zip
Fix crash with .env files that are exactly 159 bytes long (#3369)
* Fix crash with .env files that are exactly 158 bytes and a newline character * Update env_loader.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/env_loader.zig15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 7d506a04e..8a3838101 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -884,18 +884,21 @@ pub const Loader = struct {
defer file.close();
const stat = try file.stat();
- if (stat.size == 0) {
+ const end = stat.size;
+
+ if (end == 0) {
@field(this, base) = logger.Source.initPathString(base, "");
return;
}
- var buf = try this.allocator.allocSentinel(u8, stat.size, 0);
+ var buf = try this.allocator.alloc(u8, end + 1);
errdefer this.allocator.free(buf);
- var contents = try file.readAll(buf);
+ const amount_read = try file.readAll(buf[0..end]);
+
+ // The null byte here is mostly for debugging purposes.
+ buf[end] = 0;
- // always sentinel
- buf.ptr[contents + 1] = 0;
- const source = logger.Source.initPathString(base, buf.ptr[0..contents :0]);
+ const source = logger.Source.initPathString(base, buf[0..amount_read]);
Parser.parse(
&source,