Skip to content

Conversation

@Martin-Zeithaml
Copy link
Contributor

@Martin-Zeithaml Martin-Zeithaml commented Sep 25, 2025

Changes

Fixes #76.

Problem 1

You can define such string in YAML.

zowe:
  environments:
    TEST1: TE\"ST    # 'T' + 'E' + '\' + '"' + 'S' + 'T' => "TE\\\"ST"
    TEST2: 123

When trying to run internal start prepare:

ZWE_zowe_runtimeDirectory="/zowe" ZWE_CLI_PARAMETER_HA_INSTANCE="ha1" TEST1="TE\\"ST" TEST2=123...

Because of incorrect escape, the variable TEST1 will break the command, correct escaping is "TE\\\"ST".

Note: Such example is good one, because the command fails and launcher ends. But if you chain couple of wrong variables, it could end by creating unexpected variable.

Problem 2

You can define such environment variable in YAML. This variable should be ignored, otherwise launcher tries to set 1=1.

zowe:
  environments:
    1:1

escape_string solving Problem 1

This function was escaping only ". Updated to escape \ too.

is_valid_key solving Problem 2

  • Function (used just once) renamed to reflect what is trying to detect
  • It follows the syntax for unix variable name: "first char is not a digit & (any char is alphaNum | underscore)"

test/environments.sh

  • Added new test, however it is challenging to compare strings with escape sequences in unix... The tests only prints Launcher's output and zowe.yaml.
  • Added test for ignoring non-unix variable names.
! ---zowe.environments.TEST_VAR_* expected to be used or ignored ---

  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 3 is TEST_VAR_START="\S\T\A\R\T"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 4 is TEST_VAR_BOOL_01=true
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 5 is TEST_VAR_BOOL_02=false
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 6 is TEST_VAR_BOOL_03=true
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 7 is TEST_VAR_BOOL_04=false
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 8 is TEST_VAR_INT_01=123456
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 9 is TEST_VAR_INT_02=123456
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 10 is TEST_VAR_INT_03="0x7FFFFFFF"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 11 is TEST_VAR_INT_04="0x00000001"
- Key 'TEST_VAR_INT_05' not found!
- Key 'TEST_VAR_INT_06' not found!
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 12 is TEST_VAR_INT_07=9223372036854775807
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 13 is TEST_VAR_INT_08=9223372036854775807
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 14 is TEST_VAR_INT_09="-9223372036854775808"
- Key 'TEST_VAR_INT_10' not found!
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 15 is TEST_VAR_STR_01="\\\\\\\\\\"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 16 is TEST_VAR_STR_02="\\\\\\\\\\"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 17 is TEST_VAR_STR_03="\"\"\"\"\"\"\"\"\"\""
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 18 is TEST_VAR_STR_04="\""
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 19 is TEST_VAR_STR_05="\n"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 21 is TEST_VAR_STR_07="TE\\"ST"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 22 is TEST_VAR_STR_08="TE\"ST"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 23 is TEST_VAR_STR_09="TE\\"ST"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 24 is TEST_VAR_STR_10=123
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 25 is TEST_VAR_STR_11=true
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 26 is TEST_VAR_STR_12="Love all, trust a few,
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 27 is TEST_VAR_EJS_01=123456
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 28 is TEST_VAR_EJS_02=8
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 29 is TEST_VAR_EJS_03="EJS"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 30 is TEST_VAR_EJS_04="EJS"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 31 is TEST_VAR_EJS_05="EJS"
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 32 is TEST_VAR_EJS_06="EJS"
- Key 'TEST_VAR_EJS_07' not found!
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 33 is TEST_VAR_EJS_08=true
  OK: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID DEBUG shared env pos 34 is TEST_VAR_END="\E\N\D"

! ---zowe.environments.* expected to be ignored ---

  OK: Key '`zowe.environments.-key-`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.-key-` is invalid and it will be ignored
  OK: Key '`zowe.environments.?key`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.?key` is invalid and it will be ignored
  OK: Key '`zowe.environments.1+1`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.1+1` is invalid and it will be ignored
  OK: Key '`zowe.environments.1-1`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.1-1` is invalid and it will be ignored
  OK: Key '`zowe.environments._!_`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments._!_` is invalid and it will be ignored
  OK: Key '`zowe.environments.1TEST`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.1TEST` is invalid and it will be ignored
  OK: Key '`zowe.environments.3_141592`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.3_141592` is invalid and it will be ignored
  OK: Key '`zowe.environments.()`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.()` is invalid and it will be ignored
  OK: Key '`zowe.environments.~null`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.~null` is invalid and it will be ignored
  OK: Key '`zowe.environments.=`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.=` is invalid and it will be ignored
  OK: Key '`zowe.environments.<h1>`' found: 2025-09-30 09:34:57.940 <ZWELNCH:330366> USERID WARN Key in configuration `zowe.environments.<h1>` is invalid and it will be ignored

test/fakeRuntime

This is needed for running new test. Schema files were updated to be small, it does not matter for this test.

test/files/zowe.environments.yaml

  • TEST_VAR* for testing Problem 1
  • Section # *** Ignored keys *** for testing of Problem 2
  • zowe.runtimeDirectory must be absolute path, resolved with os.realpath.

Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
@Martin-Zeithaml Martin-Zeithaml changed the title V3.x/bugfix/envs Escape \ in environment variable Sep 25, 2025
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
@Martin-Zeithaml Martin-Zeithaml marked this pull request as ready for review September 25, 2025 12:26
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
src/main.c Outdated
static bool is_valid_key(char *key) {
// Zowe.environments key must follow Unix variable name syntax:
// alphaNum | underscore & first char is not a digit
static bool is_key_valid_unix_name(char *key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you could make this const char *key while you're at it :)

src/main.c Outdated

static bool is_valid_key(char *key) {
// Zowe.environments key must follow Unix variable name syntax:
// alphaNum | underscore & first char is not a digit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precedence of the operators is not very obvious. Could you add parenthesis?

(alphaNum | underscore) & first char is not a digit

Or just write it like this:

// Zowe.environments key must follow Unix variable name syntax:
// * The first char must not be a digit
// * Any characters must be either alphanumeric or an underscore

@ifakhrutdinov
Copy link
Contributor

The C part looks good to me. Since I don't really know the current state of the launcher, @1000TurquoisePogs could you review the "big picture" of this change? and the shell stuff :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Environment variable management issue

3 participants