Skip to content

Commit

Permalink
Fix possibly overwriting the null terminator on the end of type buffer
Browse files Browse the repository at this point in the history
Also use show_values instead of BUFFER_SIZE / 6 since the remaining bytes is
what matters to check whether the data was truncated or not
  • Loading branch information
Lekensteyn committed Oct 22, 2011
1 parent e04d9e8 commit b0e0d20
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions acpi_call.c
Expand Up @@ -47,12 +47,12 @@ static int acpi_result_to_string(union acpi_object *result) {
sprintf(get_buffer_end(),
i == 0 ? "0x%02x" : ", 0x%02x", result->buffer.pointer[i]);

if (result->buffer.length > BUFFER_SIZE / 6) {
// if data was truncated, show a trailing comma
sprintf(get_buffer_end(), ",");
if (result->buffer.length > show_values) {
// if data was truncated, show a trailing comma if there is space
snprintf(get_buffer_end(), get_avail_bytes(), ",");
return 1;
} else {
// in case the show_value == 0, but the buffer is too small to hold
// in case show_values == 0, but the buffer is too small to hold
// more values (i.e. the buffer cannot have anything more than "{")
snprintf(get_buffer_end(), get_avail_bytes(), "}");
}
Expand Down

0 comments on commit b0e0d20

Please sign in to comment.