Skip to content
Browse files

Correctly display timestamp in blackbox

On little endian architectures where time_t is 64-bit long integer could
happen, that instead of displaying correct timestamp, random data was
used, because of memcpy.

Solution is to memcpy to real 32-bit variable and then assing this value
to timestamp. This will let compiler decide endianity and store number
correctly.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information...
1 parent 955d43e commit a4411105a7bb9354f5ee318e356bd0595ed06e1c @jfriesse jfriesse committed with asalkeld
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/log_blackbox.c
View
4 lib/log_blackbox.c
@@ -165,6 +165,7 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
uint32_t len;
time_t timestamp;
char message[QB_LOG_MAX_LEN];
+ uint32_t u32;
bytes_read = qb_rb_chunk_read(instance, chunk, 512, 0);
ptr = chunk;
@@ -182,7 +183,8 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
ptr += fn_size;
/* timestamp size & content */
- memcpy(&timestamp, ptr, sizeof(uint32_t));
+ memcpy(&u32, ptr, sizeof(uint32_t));
+ timestamp = u32;
ptr += sizeof(time_t);
tm = localtime(&timestamp);
if (tm) {

0 comments on commit a441110

Please sign in to comment.
Something went wrong with that request. Please try again.