Share

google-ctemplate

Tracker: Patches

5 remove g++ extension from UrlQueryEscape - ID: 1638416
Last Update: Comment added ( csilvers )

char out[max_string_length] -> string out; out.reserve(max_string_length)


string TemplateDictionary::UrlQueryEscape::operator()(const string& in)
const {
// Everything not matching [0-9a-zA-Z.,_:*/~!()-] is escaped.
static unsigned long _unsafe_characters[8] = {
0xffffffffL, 0xf80008fdL, 0x78000001L, 0xb8000001L,
0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL
};

int max_string_length = in.size() * 3 + 1;
string out;
out.reserve(max_string_length);

for (int i = 0; i < in.size(); i++) {
unsigned char c = in[i];
if (c == ' ') {
out += '+';
} else if (!(_unsafe_characters[(c)>>5] & (1 << ((c) & 31)))) {
out += c;
} else {
out += '%';
out += ((c>>4) < 10 ? ((c>>4) + '0') : (((c>>4) - 10) + 'A'));
out += ((c&0xf) < 10 ? ((c&0xf) + '0') : (((c&0xf) - 10) + 'A'));
}
}
return out;
}


sfdivan ( sfdivan ) - 2007-01-18 10:10

5

Closed

Fixed

Nobody/Anonymous

None

None

Public


Comment ( 1 )




Date: 2007-01-25 23:59
Sender: csilversProject Admin


Dangerous not only because it's a gcc extension, but also because it could
cause a stack overflow. A similar fix to this patch has been applied for
the next release.


Log in to comment.

Attached File

No Files Currently Attached

Changes ( 3 )

Field Old Value Date By
status_id Open 2007-01-25 23:59 csilvers
resolution_id None 2007-01-25 23:59 csilvers
close_date - 2007-01-25 23:59 csilvers