Skip to content

Commit

Permalink
webos: bootd: Logger.cpp: fix segfault with 64bit time_t
Browse files Browse the repository at this point in the history
:Release Notes:
It was already reported by gcc in log.do_compile:
../git/src/bootd/util/Logger.cpp:124:20: warning: format '%ld' expects argument of type 'long int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]
../git/src/bootd/event/DynamicEventDB.cpp:315:28: warning: format '%ld' expects argument of type 'long int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Wformat=]
but it wasn't fatal for the build, "only" causes segfault in runtime.

:Detailed Notes:
Fixes:
  Program received signal SIGSEGV, Segmentation fault.
  __GI_strlen () at ../sysdeps/i386/i586/strlen.S:50
  warning: Source file is more recent than executable.
  50              cmpb %dh, (%eax)        /* is byte NUL? */
  (gdb) bt
  #0  __GI_strlen () at ../sysdeps/i386/i586/strlen.S:50
  #1  0xb760fb49 in __printf_buffer (buf=0xbffff030, format=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n", ap=0xbffff89c "\251\271B", mode_flags=2) at /usr/src/debug/glibc/2.40+git/stdio-common/vfprintf-process-arg.c:435
  #2  0xb762f64f in __vdprintf_internal (d=870436166, format=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n", arg=0xbffff88c "\350\270B", mode_flags=2) at iovdprintf.c:69
  webosose#3  0xb76dd7d3 in __dprintf_chk (d=4, flag=1, format=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n") at dprintf_chk.c:33
  webosose#4  0x00429a95 in dprintf (__fd=<optimized out>, __fmt=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n") at /usr/include/bits/stdio2.h:174
  webosose#5  Logger::writeBootdLog (this=0x435440 <g_Logger>, type=0x42b8e8 "PERFORMANCE", msgid=0x42b9a9 "Boot", msg=0x43544c <g_Logger+12> "BOOTD_START") at /usr/src/debug/bootd/2.0.0-23/src/bootd/util/Logger.cpp:123
  webosose#6  0x00429bdf in Logger::performanceLog (this=0x435440 <g_Logger>, msgid=0x42b9a9 "Boot", format=0x42b008 "BOOTD_START") at /usr/src/debug/bootd/2.0.0-23/src/bootd/util/Logger.cpp:143
  webosose#7  0x0040fbf8 in main (argc=1, argv=0xbffffa54) at /usr/src/debug/bootd/2.0.0-23/src/bootd/Main.cpp:44

:Testing Performed:
Local Test: OK

:QA Notes:

:Issues Addressed:
[WRQ-32812] bootd segfaults with 64-bit time_t

Change-Id: I45ed378ac1212a6ecbcdf84479d721c2960641c5
  • Loading branch information
shr-project committed Aug 19, 2024
1 parent ad6b15c commit dd9d84f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
4 changes: 3 additions & 1 deletion meta-webos/recipes-webos/bootd/bootd.bb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ inherit webos_lttng
inherit webos_public_repo
inherit webos_prerelease_dep

SRC_URI = "${WEBOSOSE_GIT_REPO_COMPLETE}"
SRC_URI = "${WEBOSOSE_GIT_REPO_COMPLETE} \
file://0002-Logger.cpp-fix-segfault-with-64bit-time_t.patch \
"
S = "${WORKDIR}/git"

inherit webos_systemd
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
From f6efaccc5c8f90100880cb588bcfbab84e274a75 Mon Sep 17 00:00:00 2001
From: Martin Jansa <martin2.jansa@lgepartner.com>
Date: Mon, 19 Aug 2024 17:07:20 +0200
Subject: [PATCH] Logger.cpp: fix segfault with 64bit time_t

:Release Notes:
It was already reported by gcc in log.do_compile:
../git/src/bootd/util/Logger.cpp:124:20: warning: format '%ld' expects argument of type 'long int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]
../git/src/bootd/event/DynamicEventDB.cpp:315:28: warning: format '%ld' expects argument of type 'long int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Wformat=]
but it wasn't fatal for the build, "only" causes segfault in runtime.

:Detailed Notes:
Fixes:
Program received signal SIGSEGV, Segmentation fault.
__GI_strlen () at ../sysdeps/i386/i586/strlen.S:50
warning: Source file is more recent than executable.
50 cmpb %dh, (%eax) /* is byte NUL? */
(gdb) bt
#0 __GI_strlen () at ../sysdeps/i386/i586/strlen.S:50
#1 0xb760fb49 in __printf_buffer (buf=0xbffff030, format=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n", ap=0xbffff89c "\251\271B", mode_flags=2) at /usr/src/debug/glibc/2.40+git/stdio-common/vfprintf-process-arg.c:435
#2 0xb762f64f in __vdprintf_internal (d=870436166, format=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n", arg=0xbffff88c "\350\270B", mode_flags=2) at iovdprintf.c:69
#3 0xb76dd7d3 in __dprintf_chk (d=4, flag=1, format=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n") at dprintf_chk.c:33
#4 0x00429a95 in dprintf (__fd=<optimized out>, __fmt=0x42b8cf "%s(%3ld.%09ld) : %s) %s\n") at /usr/include/bits/stdio2.h:174
#5 Logger::writeBootdLog (this=0x435440 <g_Logger>, type=0x42b8e8 "PERFORMANCE", msgid=0x42b9a9 "Boot", msg=0x43544c <g_Logger+12> "BOOTD_START") at /usr/src/debug/bootd/2.0.0-23/src/bootd/util/Logger.cpp:123
#6 0x00429bdf in Logger::performanceLog (this=0x435440 <g_Logger>, msgid=0x42b9a9 "Boot", format=0x42b008 "BOOTD_START") at /usr/src/debug/bootd/2.0.0-23/src/bootd/util/Logger.cpp:143
#7 0x0040fbf8 in main (argc=1, argv=0xbffffa54) at /usr/src/debug/bootd/2.0.0-23/src/bootd/Main.cpp:44

:Testing Performed:
Local Test: OK

:QA Notes:

:Issues Addressed:
[WRQ-32812] bootd segfaults with 64-bit time_t

Change-Id: I45ed378ac1212a6ecbcdf84479d721c2960641c5
---
Upstream-Status: Submitted [http://gpro.lge.com/c/webosose/bootd/+/428559 Logger.cpp: fix segfault with 64bit time_t]

src/bootd/event/DynamicEventDB.cpp | 2 +-
src/bootd/util/Logger.cpp | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/bootd/event/DynamicEventDB.cpp b/src/bootd/event/DynamicEventDB.cpp
index e2de0d3..acf61b6 100644
--- a/src/bootd/event/DynamicEventDB.cpp
+++ b/src/bootd/event/DynamicEventDB.cpp
@@ -312,7 +312,7 @@ void DynamicEventDB::callEventListeners(string eventName, EventHandleType type)
struct timespec curTime;
char timeBuffer[256] = { 0, };
g_Logger.getCurrentTime(curTime);
- sprintf(timeBuffer, "%ld.%09ld", curTime.tv_sec, curTime.tv_nsec);
+ sprintf(timeBuffer, "%jd.%09jd", (intmax_t)curTime.tv_sec, (intmax_t)curTime.tv_nsec);
m_eventDatabase[eventName].put(KEY_TIME, timeBuffer);
}

diff --git a/src/bootd/util/Logger.cpp b/src/bootd/util/Logger.cpp
index 190e9ce..cbc1c26 100644
--- a/src/bootd/util/Logger.cpp
+++ b/src/bootd/util/Logger.cpp
@@ -121,10 +121,10 @@ void Logger::writeBootdLog(const char *type, const char *msgid, const char *msg)
return;

dprintf(m_fdBootdLog,
- "%s(%3ld.%09ld) : %s) %s\n",
+ "%s(%3jd.%09jd) : %s) %s\n",
type,
- curTime.tv_sec,
- curTime.tv_nsec,
+ (intmax_t)curTime.tv_sec,
+ (intmax_t)curTime.tv_nsec,
msgid,
msg);
}

0 comments on commit dd9d84f

Please sign in to comment.