Skip to content

Commit 557818c

Browse files
besser82solardiz
authored andcommitted
libnss_tcb: Drop use of readdir_r(3).
In commit 72ef702 we introduced a replacement for the deprecated readdir_r(3) by using readdir(3) with global thread-local storage. As almost any operating system released within the last eight years supports thread-local storage natively, there is little to no reason keeping the potentially dangerous fallback to readdir_r(3). Signed-off-by: Björn Esser <[email protected]>
1 parent c82b107 commit 557818c

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
* progs/Makefile: Likewise.
2020
* LICENSE: Update copyright for this contribution.
2121

22+
libnss_tcb: Drop use of readdir_r(3).
23+
In commit 72ef702a886c8a9749bdc01d89a57cdf0455318c we introduced a
24+
replacment for the deprecated readdir_r(3) by using readdir(3) with
25+
global thread-local storage. As almost any operating system released
26+
within the last eight years supports thread-local storage natively,
27+
there is little to no reason keeping the potentially dangerous
28+
fallback to readdir_r(3).
29+
* libs/nss.c (_nss_tcb_getspnam_r): Drop use of readdir_r(3).
30+
2231
2024-10-17 Dmitry V. Levin <ldv at owl.openwall.com>
2332

2433
pam_tcb: Do not use deprecated _pam_overwrite macro.

libs/nss.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111

1212
#include "tcb.h"
1313

14-
/* readdir_r(3) is deprecated since glibc 2.24 */
15-
#if defined __GLIBC_PREREQ && __GLIBC_PREREQ(2, 24)
16-
#define USE_READDIR 1
17-
#else
18-
#define USE_READDIR 0
19-
#endif
20-
21-
#if USE_READDIR
2214
static __thread DIR *tcbdir = NULL;
23-
#else
24-
static DIR *tcbdir = NULL;
25-
#endif
2615

2716
int _nss_tcb_setspent(void)
2817
{
@@ -107,9 +96,6 @@ int _nss_tcb_getspnam_r(const char *name, struct spwd *__result_buf,
10796
int _nss_tcb_getspent_r(struct spwd *__result_buf,
10897
char *__buffer, size_t __buflen, struct spwd **__result)
10998
{
110-
#if !USE_READDIR
111-
struct dirent entry;
112-
#endif
11399
struct dirent *result;
114100
off_t currpos;
115101
int retval, saved_errno;
@@ -122,15 +108,10 @@ int _nss_tcb_getspent_r(struct spwd *__result_buf,
122108

123109
do {
124110
currpos = telldir(tcbdir);
125-
#if USE_READDIR
126111
saved_errno = errno;
127112
errno = 0;
128113
result = readdir(tcbdir);
129114
if (!result && errno) {
130-
#else
131-
if (readdir_r(tcbdir, &entry, &result)) {
132-
saved_errno = errno;
133-
#endif
134115
closedir(tcbdir);
135116
errno = saved_errno;
136117
tcbdir = NULL;
@@ -142,9 +123,7 @@ int _nss_tcb_getspent_r(struct spwd *__result_buf,
142123
tcbdir = NULL;
143124
return NSS_STATUS_NOTFOUND;
144125
}
145-
#if USE_READDIR
146126
errno = saved_errno;
147-
#endif
148127
} while (!strcmp(result->d_name, ".") ||
149128
!strcmp(result->d_name, "..") || result->d_name[0] == ':');
150129

0 commit comments

Comments
 (0)