Skip to content
This repository

Fix parsing badly formed environment variables #313

Closed
wants to merge 1 commit into from

2 participants

Sergey Yelin Tuncer Ayaz
Sergey Yelin

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.

Sergey Yelin

This issue need more investigation.

Sergey Yelin kpy3 closed this October 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 18, 2012
Sergey Yelin Fix parsing badly formed environment variables bc0021d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 14 additions and 4 deletions. Show diff stats Hide diff stats

  1. 18  src/rebar_port_compiler.erl
18  src/rebar_port_compiler.erl
@@ -440,10 +440,20 @@ erts_dir() ->
440 440
     lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
441 441
 
442 442
 os_env() ->
443  
-    Os = [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) ||
444  
-             S <- os:getenv()],
445  
-    %% Drop variables without a name (win32)
446  
-    [T1 || {K, _V} = T1 <- Os, K =/= []].
  443
+    lists:reverse(
  444
+        lists:foldl(
  445
+            fun({'EXIT',{badarg, _}}, Env) ->
  446
+                   %% Skip variable which can not be parsed
  447
+                   Env; 
  448
+               ([[],_], Env) ->
  449
+                   %% Drop variables without a name (win32)
  450
+                   Env;
  451
+               ([_,_] = Tokens, Env) ->
  452
+                   [list_to_tuple(Tokens) | Env]
  453
+            end,
  454
+            [],
  455
+            [catch(re:split(S, "=", [{return, list}, {parts, 2}])) || 
  456
+                S <- os:getenv()])).
447 457
 
448 458
 select_compile_template(drv, Compiler) ->
449 459
     select_compile_drv_template(Compiler);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.