2 ms·
I would be careful using this with data from untrusted sources without knowing exactly what you are doing, especially if you don't provide any hard limits of le
by A1kmm 16y ago
I would be careful using this with data from untrusted sources without knowing exactly what you are doing, especially if you don't provide any hard limits of length of URL data from users.
e.g. within a few minutes of looking, I found this:
void Append(const T* str, int str_len) {
if (cur_len_ + str_len > buffer_len_) {
if (!Grow(cur_len_ + str_len - buffer_len_))
return;
}
for (int i = 0; i < str_len; i++)
buffer_[cur_len_ + i] = str[i];
cur_len_ += str_len;
}
cur_len_, buffer_len_, and str_len are all signed int (31 bits on most modern 32 and 64 bit compilers). Say cur_len_ is 1000, buffer_len_ is 1024, and I convince the program to call append with a string of length 2147483647 (2^31 - 1). Then cur_len_ + str_len = 2147483647 + 1000 = -2147482649 < 1024, so the first if passes, and my data gets copied to the heap past the end of the allocated buffer.
This might crash the program in this case, but if I have more memory and can control all parts of the URL, I could arrange to only write a few bytes over, change headers used by the allocator, and exploit the system.
It took me longer to write this comment than it did to find something dubious in the codebase, so I'd strongly suggest auditing the library carefully before using it.