Skip to content

Commit

Permalink
Fix: trim whitespace from certain DSN fields (#189)
Browse files Browse the repository at this point in the history
Trim whitespace from Cloud ID, User and Host field values before
submitting these to the driver
(WS is likely to be inserted if copy&pasting these values.)

Also, rephrase the error message presented to the user in case the Cloud
ID is incorrect.

(cherry picked from commit c4b36bb)
  • Loading branch information
bpintea committed Nov 14, 2019
1 parent f553b9a commit 9dc3cec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,7 @@ static BOOL decode_cloud_id(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
if (Curl_base64_decode(buff, &dec, &len) != CURLE_OK) {
ERRH(dbc, "failed to decode B64 part of Cloud ID: [%zu] `" LWPDL "`.",
attrs->cloud_id.cnt, LWSTR(&attrs->cloud_id));
SET_HDIAG(dbc, SQL_STATE_HY000, "Invalid Base64 encoding in Cloud ID "
"parameter", 0);
SET_HDIAG(dbc, SQL_STATE_HY000, "Invalid Cloud ID parameter", 0);
return FALSE;
}
DBGH(dbc, "Cloud ID decoded to: [%zu] `" LCPDL "`.", len, len, dec);
Expand Down
9 changes: 6 additions & 3 deletions dsneditor/EsOdbcDsnEditor/DSNEditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,13 @@ private bool RebuildAndValidateDsn()
// Basic Panel
Builder["dsn"] = textName.Text;
Builder["description"] = textDescription.Text;
Builder["uid"] = textUsername.Text;
// https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-user.html#security-api-put-user-path-params :
// "Leading or trailing whitespace is not allowed." -> it is more likely that a user will insert a
// (trailing) white space by mistake than intentionally trying to set it.
Builder["uid"] = textUsername.Text.Trim();
Builder["pwd"] = textPassword.Text;
Builder["cloudid"] = "{" + textCloudID.Text.StripBraces() + "}";
Builder["server"] = textHostname.Text;
Builder["cloudid"] = "{" + textCloudID.Text.StripBraces().Trim() + "}";
Builder["server"] = textHostname.Text.Trim();
Builder["port"] = numericUpDownPort.Text;

// Security Panel
Expand Down

0 comments on commit 9dc3cec

Please sign in to comment.