Github user zellerh commented on a diff in the pull request:
https://github.com/apache/trafodion/pull/1623#discussion_r198553974
--- Diff: core/sql/cli/CliExpExchange.cpp ---
@@ -3383,6 +3383,94 @@ InputOutputExpr::inputRowwiseRowsetValues(atp_struct
*atp,
return ex_expr::EXPR_ERROR;
}
+void handleCharsetPerfix(Descriptor * inputDesc)
+{
+ char perfix[MAX_CHAR_SET_STRING_LENGTH];
+
+ if(inputDesc)
+ {
+ for (Lng32 entry = 1; entry <= inputDesc->getUsedEntryCount();
++entry)
+ {
+ Lng32 perfix_beg = -1;
+ Lng32 perfix_end = 0;
+ char* source = inputDesc->getVarData(entry);
+ Lng32 valueLength = inputDesc->getVarDataLength(entry);
+ if (source)
+ {
+ // get charset perfix beg loc
+ for (Lng32 i = 0; i < valueLength && i <
MAX_CHAR_SET_STRING_LENGTH; ++i)
+ {
+ if(source[i] == '_' || TOUPPER(source[i]) =='N')
+ {
+ perfix_beg = i;
+ break;
+ }
+
+ if (source[i] == '\'')
+ return;
+ }
+
+ if (perfix_beg < 0)
+ return;
+
+ // get charset perfix end loc
+ Lng32 perfix_ind = 0;
+
+ if (source[perfix_beg] == 'N')
+ {
+ perfix[perfix_ind] = 'N';
+ perfix_ind = 1;
+ }
+
+ for (Lng32 i = perfix_beg+1; i < valueLength && i <
MAX_CHAR_SET_STRING_LENGTH; ++i)
+ {
+ if(source[i] != '\'' && source[i] != 0)
+ {
+ perfix[perfix_ind] = TOUPPER(source[i]);
+ ++perfix_ind;
+ }
+
+ if(source[i] == '\'')
+ {
+ perfix[perfix_ind] = 0;
+ perfix_end = i;
+ break;
+ }
+ }
+
+ //perfix_cs
+ CharInfo::CharSet cs = CharInfo::getCharSetEnum(perfix);
+ if(str_len(perfix) == 1 AND perfix[0] == 'N')
+ cs = CharInfo::UNICODE;
+
+ //if perfix_cs is UnknownCharSet direct return
+ if(cs == CharInfo::UnknownCharSet)
+ return;
+
+ // remove cs
+ Lng32 valEnd = 0;
+ for (Lng32 i = perfix_end+1; i < valueLength; ++i)
+ {
+ if (source[i] == '\'')
+ {
+ valEnd = i-1;
+ break;
+ }
+ }
+ Lng32 valBeg = perfix_end+1;
+ if (!source[valBeg])
+ {
+ valBeg += 1;
+ }
+ memcpy(&source[perfix_beg], &source[valBeg],
valEnd-valBeg+1);
+ memcpy(&source[valEnd-valBeg+1+perfix_beg],
&source[valEnd+3], valBeg+2);
--- End diff --
Wouldn't this copy uninitialized memory beyond the end of the value? This
also shows a problem, that you would need to shorten the string. Another
indicator that maybe the bug is in trafci and not here (see comment below).
---