Skip to content

Commit 8c95e9e

Browse files
GUIDINGLIDonny9
authored andcommitted
freopen: fix fdsan report error
[<0x60ddce>] __assert+0x1d/0x5c [<0x60f2be>] android_fdsan_exchange_owner_tag+0x71/0xc0 [<0x60a14e>] close+0x19/0x64 [<0xb77b1c>] freopen+0x47/0xd8 [<0x86fe54>] test_nuttx_fs_stream01+0x4f/0x1a4 [<0xcef54e>] cmocka_run_one_test_or_fixture+0xe5/0x3cc [<0xcefd26>] _cmocka_run_group_tests+0x41d/0xbd8 [<0x86cff2>] cmocka_fs_test_main+0x35/0x58 [<0x6a9d1a>] nxtask_startup+0x15/0x30 [<0x641e92>] nxtask_start+0x75/0x94 Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent a8280b0 commit 8c95e9e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

libs/libc/stdio/lib_freopen.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <errno.h>
3232
#include <unistd.h>
3333

34+
#ifdef CONFIG_FDSAN
35+
# include <android/fdsan.h>
36+
#endif
37+
3438
#include "libc.h"
3539

3640
/****************************************************************************
@@ -113,11 +117,22 @@ FAR FILE *freopen(FAR const char *path, FAR const char *mode,
113117

114118
/* close the old fd */
115119

120+
#ifdef CONFIG_FDSAN
121+
android_fdsan_close_with_tag(fileno(stream),
122+
android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_FILE,
123+
(uintptr_t)stream));
124+
#else
116125
close(fileno(stream));
126+
#endif
117127

118128
/* Open the new file and reused the fd */
119129

120130
fd = open(path, oflags, 0666);
131+
#ifdef CONFIG_FDSAN
132+
android_fdsan_exchange_owner_tag(fd, 0,
133+
android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_FILE,
134+
(uintptr_t)stream));
135+
#endif
121136
flockfile(stream);
122137
stream->fs_cookie = (FAR void *)(intptr_t)fd;
123138
funlockfile(stream);

0 commit comments

Comments
 (0)