Skip to content

Commit

Permalink
Fix a condition in utilities::logger::append_newline
Browse files Browse the repository at this point in the history
The previous condition assumes enough space to append an extra newline
followed by \0. If we already have a full message buffer, appending would
overflow and the \0 would corrupt some adjacent variable. If this
adjacent variable happens to be the guard from the calling function,
it would be corrupted and fails to unlock its lock, causing other
logging components to stuck forever waiting for that lock.
  • Loading branch information
ahmadsherif committed Feb 24, 2016
1 parent 928f49b commit 0b4b712
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion vm/util/logger.cpp
Expand Up @@ -54,7 +54,7 @@ namespace rubinius {
char* end = (char*)memchr(message, '\0', LOGGER_MSG_SIZE);
size_t bytes = end ? end - message : LOGGER_MSG_SIZE;

if(bytes < LOGGER_MSG_SIZE) {
if(LOGGER_MSG_SIZE - bytes > 1) {
if(message[bytes-1] != '\n') {
message[bytes] = '\n';
message[bytes += 1] = '\0';
Expand Down

0 comments on commit 0b4b712

Please sign in to comment.