Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
All notable changes to the Zowe Launcher package will be documented in this file.
This repo is part of the app-server Zowe Component, and the change logs here may appear on Zowe.org in that section.

## 2.18.4
- Bugfix: Escape backslash when used in environment variable ([#169](https://github.com/zowe/launcher/pull/169))

## 2.18.1
- Bugfix: HEAPPOOLS and HEAPPOOLS64 no longer need to be set to OFF for launcher (#132)

Expand Down
25 changes: 19 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,19 @@ static bool arrayListContains(ArrayList *list, char *element) {
static char* escape_string(char *input) {
int length = strlen(input);
int quotes = 0;
int backSlashes = 0;
for (int i = 0; i < length; i++) {
if (input[i] == '\"') quotes++;
if (input[i] == '\\') backSlashes++;
}

char *output = malloc(length + quotes + 2 + 1); // add quote on first and the last position and escape quotes inside
// 2 + 1 = add quote on first and the last position and \0 at the end
// quotes & backSlashes = add '\' to escape '"' and '\'
char *output = malloc(length + quotes + backSlashes + 2 + 1);
output[0] = '\"';
int j = 1;
for (int i = 0; i < length; i++) {
if (input[i] == '\"') {
if (input[i] == '\"' || input[i] == '\\') {
output[j++] = '\\';
}
output[j++] = input[i];
Expand All @@ -431,7 +435,7 @@ static char* jsonToString(Json *json) {
return jsonAsBoolean(json) ? "true" : "false";
case JSON_TYPE_NUMBER:
case JSON_TYPE_INT64:
output = malloc(21); // Longest string possible -9223372036854775807
output = malloc(21); // Longest string possible -9223372036854775808
snprintf(output, 21, "%ld", jsonAsInt64(json));
return output;
case JSON_TYPE_DOUBLE:
Expand All @@ -443,11 +447,20 @@ static char* jsonToString(Json *json) {
}
}

static bool is_valid_key(char *key) {
// 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
static bool is_key_valid_unix_name(const char *key) {
int length = strlen(key);
if (!length) {
return false;
}
if (isdigit(key[0])) {
return false;
}
for (int i = 0; i < length; i++) {
if (isalnum(key[i])) continue;
if (strchr("_-", key[i])) continue;
if (key[i] == '_') continue;
return false;
}
return true;
Expand Down Expand Up @@ -503,7 +516,7 @@ static void set_shared_uss_env(ConfigManager *configmgr) {
// Get all environment variables defined in zowe.yaml and put them in the output as they are
for (JsonProperty *property = jsonObjectGetFirstProperty(object); property != NULL; property = jsonObjectGetNextProperty(property)) {
char *key = jsonPropertyGetKey(property);
if (!is_valid_key(key)) {
if (!is_key_valid_unix_name(key)) {
WARN("Key in zowe.yaml `zowe.environments.%s` is invalid and it will be ignored\n", key);
continue;
}
Expand Down
Loading