Skip to content

Commit

Permalink
Safely log NULL buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlynch committed Feb 18, 2024
1 parent 0bfc384 commit 425424b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tools/print_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file print_helpers.c
* @brief Helper functions for command line output
*
* Copyright (c) 2021, 2022 Leon Lynch
* Copyright (c) 2021-2024 Leon Lynch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -53,8 +53,12 @@ void print_buf(const char* buf_name, const void* buf, size_t length)
if (buf_name) {
printf("%s: ", buf_name);
}
for (size_t i = 0; i < length; i++) {
printf("%02X", ptr[i]);
if (buf) {
for (size_t i = 0; i < length; i++) {
printf("%02X", ptr[i]);
}
} else {
printf("(null)");
}
printf("\n");
}
Expand Down Expand Up @@ -512,8 +516,7 @@ static void print_emv_debug_internal(
} else {
switch (debug_type) {
case EMV_DEBUG_TYPE_TLV:
printf("%s: ", str);
print_buf(NULL, buf, buf_len);
print_buf(str, buf, buf_len);
print_emv_buf(buf, buf_len, " ", 1);
return;

Expand All @@ -522,8 +525,7 @@ static void print_emv_debug_internal(
return;

default:
printf("%s: ", str);
print_buf(NULL, buf, buf_len);
print_buf(str, buf, buf_len);
return;
}
}
Expand Down

0 comments on commit 425424b

Please sign in to comment.