8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 22:03:03 +01:00

Fixed #7106: Wrong detection of must-be-delimited user names

This commit is contained in:
AlexPeshkoff 2022-01-27 14:36:40 +03:00
parent a4c675342f
commit 47d1e8305e
2 changed files with 28 additions and 12 deletions

View File

@ -1610,6 +1610,11 @@ bool containsErrorCode(const ISC_STATUS* v, ISC_STATUS code)
return false;
}
inline bool sqlSymbolChar(char c, bool first)
{
return (isdigit(c) && !first) || isalpha(c) || c == '_' || c == '$';
}
const char* dpbItemUpper(const char* s, FB_SIZE_T l, Firebird::string& buf)
{
if (l && (s[0] == '"' || s[0] == '\''))
@ -1622,30 +1627,37 @@ const char* dpbItemUpper(const char* s, FB_SIZE_T l, Firebird::string& buf)
{
if (s[i] == end_quote)
{
if (++i >= l || s[i] != end_quote)
break; // delimited quote, done processing
// skipped the escape quote, continue processing
}
if (s[i] & 0x80)
ascii = false;
buf += s[i];
}
if (++i >= l)
{
if (ascii && s[0] == '\'')
buf.upper();
return buf.c_str();
}
if (s[i] != end_quote)
{
buf.assign(&s[i], l - i);
Firebird::fatal_exception::raiseFmt("Invalid text <%s> after quoted string", buf.c_str());
}
// skipped the escape quote, continue processing
}
else if (!sqlSymbolChar(s[i], i == 1))
ascii = false;
buf += s[i];
}
Firebird::fatal_exception::raiseFmt("Missing terminating quote <%c> in the end of quoted string", s[0]);
}
// non-quoted string - try to uppercase
for (FB_SIZE_T i = 0; i < l; ++i)
{
if (!(s[i] & 0x80))
buf += toupper(s[i]);
else
if (!sqlSymbolChar(s[i], i == 0))
return NULL; // contains non-ascii data
buf += toupper(s[i]);
}
return buf.c_str();

View File

@ -1776,7 +1776,11 @@ void UserId::makeRoleName(Firebird::MetaString& role, const int dialect)
// Invoke utility twice: first to strip quotes, next to uppercase if needed
// For unquoted string nothing bad happens
fb_utils::dpbItemUpper(role);
fb_utils::dpbItemUpper(role);
{
Firebird::string tmp(role);
tmp.upper();
role = tmp;
}
break;
case SQL_DIALECT_V6_TRANSITION: