Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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>
  • Loading branch information...
commit 554429a61f432d8cc4ee5ebfee9034008808361f 1 parent 25ce7de
@psychon psychon authored
Showing with 7 additions and 4 deletions.
  1. +7 −4 ZNCString.cpp
View
11 ZNCString.cpp
@@ -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 += ";";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.