summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sami Kortelainen2026-02-13 07:36:46 +0200
committerGravatar Sami Kortelainen2026-02-14 19:17:26 +0200
commit61636353617271a7a25335111a8b4dfc7a70a139 (patch)
tree3a568ab702b283a770815f929da439cd6c4f4590
parent74e3bd9286d16fc1290abde061ee00831d5b36f8 (diff)
downloadidevicerestore-61636353617271a7a25335111a8b4dfc7a70a139.tar.gz
idevicerestore-61636353617271a7a25335111a8b4dfc7a70a139.tar.bz2
logger: fix crash and undefined behavior in logger_dump_hex with zero-length buffersHEADmaster
-rw-r--r--src/log.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/log.c b/src/log.c
index b9c2c51..1238cb4 100644
--- a/src/log.c
+++ b/src/log.c
@@ -175,7 +175,15 @@ void logger_dump_hex(enum loglevel level, const void* buf, size_t len)
mutex_lock(&log_mutex);
- fs = (char*)malloc(len * 3 + 1);
+ fs = (char*)malloc((len == 0) ? 2 : (len * 3 + 1));
+ if (!fs) {
+ mutex_unlock(&log_mutex);
+ return;
+ }
+ if (len == 0) {
+ fs[0] = '\n';
+ fs[1] = '\0';
+ }
for (unsigned int i = 0; i < len; i++) {
snprintf(fs + i*3, 4, "%02x%c", ((unsigned char*)buf)[i], (i < len-1) ? ' ' : '\n');
}