Skip to content

Commit 5fa5658

Browse files
binujacob1337nashif
authored andcommitted
libc: newlibc: Fix recursive gettimeofday() calls on non-Posix systems
Calling gettimeofday() from _gettimeofday() in a non-Posix build environment can result in a recursive call loop, causing a stack overflow. Modify _gettimeofday() to return -1 for non-posix systems (the previous behaviour that was added in #22508). Fixes #41095 Signed-off-by: Binu Jacob <[email protected]>
1 parent 205b7f2 commit 5fa5658

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/libc/newlib/libc-hooks.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,5 +557,12 @@ void *_sbrk_r(struct _reent *r, int count)
557557

558558
int _gettimeofday(struct timeval *__tp, void *__tzp)
559559
{
560+
#ifdef CONFIG_POSIX_API
560561
return gettimeofday(__tp, __tzp);
562+
#else
563+
/* Non-posix systems should not call gettimeofday() here as it will
564+
* result in a recursive call loop and result in a stack overflow.
565+
*/
566+
return -1;
567+
#endif
561568
}

0 commit comments

Comments
 (0)