-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Segmentation Fault on Ubuntu 14.10 / gcc 4.9.1 #395
Comments
can you try defining |
Yes, that seems to have fixed it. |
By default WebSocket++ uses a masking system that bends the normal aliasing rules a bit for a sizable speed boost. Certain more exotic CPUs and very aggressive optimization flags are confused by this. That define forces strict masking that is slower but fully standard. |
i encountered the exact same problem with debian 7 on armv7l (BananaPi) with g++-4.9.2-10. |
Can a static_assert or some other method be used in code to catch this during development? |
Websocket++ does not "bend" the rules. It violates them which leads to undefined behavior in this function: inline void word_mask_exact(uint8_t* input, uint8_t* output, size_t length,
const masking_key_type& key)
{
size_t prepared_key = prepare_masking_key(key);
size_t n = length/sizeof(size_t);
size_t* input_word = reinterpret_cast<size_t*>(input);
size_t* output_word = reinterpret_cast<size_t*>(output);
for (size_t i = 0; i < n; i++) {
output_word[i] = input_word[i] ^ prepared_key; // this line
}
for (size_t i = n*sizeof(size_t); i < length; i++) {
output[i] = input[i] ^ key.c[i%4];
}
} The compiler may assume that any pointer to a size_t is properly aligned for a size_t. This is probably not the case for either the input or the output pointer. ARM is not exotic and "aggressive" optimization flags are the norm. It is not the compiler who is confused by this issue. |
Looking in more detail at the exact rules for portability with respect to aliasing I agree with @TyRoXx. This sort of optimization can only be done safely with platform specific SIMD systems. I will be changing the default masking code to use the slower but well defined byte based masking. |
thanks for fixing it! Please make a new release with the fix :) |
This fix has been committed and released in 0.7.0 |
Hi,
I have been using websocketpp successfully on several Mac OS and Linux systems (great library by the way). I recently moved to Ubuntu 14.10 with gcc 4.9.1 and I am now having an issue. It seems that if the client (web browser, Chrome or Firefox) sends a message that is 32 bytes or longer to the server (C++ app, websocket++), it crashes the server with a segfault. This only happens when using the -O3 compiler flag, otherwise it works correctly.
I have come up with a minimal test which reproduces it:
websockettest.cpp:
websockettest.html:
On every other system and when not using the -O3 compiler flag, this works and the server prints:
On Ubuntu 14.10/GCC 4.9.1 I get:
The segfault occurs before the
on_message
handler is fired. I could not debug it effectively with gdb since the problem only occurs with the -O3 flag, but by just usingprintf
s, I was able to narrow it down to theword_mask_circ()
function in frame.hpp. It seemed like all of the arguments were valid so I can not figure out what the problem is. I have tried 0.4.0 and the development branch.The text was updated successfully, but these errors were encountered: