Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix parsing badly formed environment variables #313

Closed
wants to merge 1 commit into from

2 participants

@kpy3

In some cases os:getenv() returns list instead of string() for environment variable (see below).

os:getenv().
["HISTFILE=/Users/yes/.zsh_history",
"ITERM_SESSION_ID=w0t1p0","PROMPT=[%n@%m:%1~]%# ",
"ITERM_PROFILE=Default","PROGNAME=erl",

[118,99,115,95,105,110,102,111,95,109,115,103|...],

"PWD=/Users/yes/Projects/rebar",
"USER=yes","vcs_info_msg_1_=",
"Apple_PubSub_Socket_Render=/tmp/launch-zugMm3/Render",
[...]|...]

When it happens rebar will crash in rebar_port_compiler:os_env/0. This patch fixes this problem.

@tuncer tuncer was assigned
@kpy3

This issue need more investigation.

@kpy3 kpy3 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 18, 2012
  1. @kpy3
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/rebar_port_compiler.erl
View
18 src/rebar_port_compiler.erl
@@ -440,10 +440,20 @@ erts_dir() ->
lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
os_env() ->
- Os = [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) ||
- S <- os:getenv()],
- %% Drop variables without a name (win32)
- [T1 || {K, _V} = T1 <- Os, K =/= []].
+ lists:reverse(
+ lists:foldl(
+ fun({'EXIT',{badarg, _}}, Env) ->
+ %% Skip variable which can not be parsed
+ Env;
+ ([[],_], Env) ->
+ %% Drop variables without a name (win32)
+ Env;
+ ([_,_] = Tokens, Env) ->
+ [list_to_tuple(Tokens) | Env]
+ end,
+ [],
+ [catch(re:split(S, "=", [{return, list}, {parts, 2}])) ||
+ S <- os:getenv()])).
select_compile_template(drv, Compiler) ->
select_compile_drv_template(Compiler);
Something went wrong with that request. Please try again.