mirror of
https://github.com/znc/znc.git
synced 2026-08-07 17:33:34 +02:00
Fix a bug in MCString::Encode()
For character values above 127, the signed char that could be used here did the wrong thing. That is, *it >> 4 returned a negative value and the array hexdigits was read indexed with that wrong value. Fix this by explicitly using unsigned char. Thanks to crocket for reporting this bug which he found with perform (broken entries after a restart/reload). Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
+7
-4
@@ -1098,12 +1098,15 @@ static const char hexdigits[] = "0123456789abcdef";
|
||||
CString& MCString::Encode(CString& sValue) const {
|
||||
CString sTmp;
|
||||
for (CString::iterator it = sValue.begin(); it != sValue.end(); ++it) {
|
||||
if (isalnum(*it)) {
|
||||
sTmp += *it;
|
||||
// isalnum() needs unsigned char as argument and this code
|
||||
// assumes unsigned, too.
|
||||
unsigned char c = *it;
|
||||
if (isalnum(c)) {
|
||||
sTmp += c;
|
||||
} else {
|
||||
sTmp += "%";
|
||||
sTmp += hexdigits[*it >> 4];
|
||||
sTmp += hexdigits[*it & 0xf];
|
||||
sTmp += hexdigits[c >> 4];
|
||||
sTmp += hexdigits[c & 0xf];
|
||||
sTmp += ";";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user