1From b546a0ae0beb2323143aed00d05e2fdf4fef5239 Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Sun, 17 Apr 2016 23:50:15 -0700
4Subject: [PATCH] fts: Avoid d_namlen
5
6---
7 lib/libc/gen/fts.c | 10 ++++++----
8 1 file changed, 6 insertions(+), 4 deletions(-)
9
10diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
11index 98b3a0a39..c186b7af2 100644
12--- a/lib/libc/gen/fts.c
13+++ b/lib/libc/gen/fts.c
14@@ -555,6 +555,7 @@ fts_build(FTS *sp, int type)
15 int nitems, cderrno, descend, level, nlinks, nostat, doadjust;
16 int saved_errno;
17 char *cp;
18+ size_t namlen;
19
20 /* Set current node pointer. */
21 cur = sp->fts_cur;
22@@ -653,11 +654,12 @@ fts_build(FTS *sp, int type)
23 if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
24 continue;
25
26- if (!(p = fts_alloc(sp, dp->d_name, dp->d_namlen)))
27+ namlen = strlen(dp->d_name);
28+ if (!(p = fts_alloc(sp, dp->d_name, namlen)))
29 goto mem1;
30- if (dp->d_namlen >= maxlen) { /* include space for NUL */
31+ if (namlen >= maxlen) { /* include space for NUL */
32 oldaddr = sp->fts_path;
33- if (fts_palloc(sp, dp->d_namlen +len + 1)) {
34+ if (fts_palloc(sp, namlen +len + 1)) {
35 /*
36 * No more memory for path or structures. Save
37 * errno, free up the current structure and the
38@@ -683,7 +685,7 @@ mem1: saved_errno = errno;
39
40 p->fts_level = level;
41 p->fts_parent = sp->fts_cur;
42- p->fts_pathlen = len + dp->d_namlen;
43+ p->fts_pathlen = len + namlen;
44 if (p->fts_pathlen < len) {
45 /*
46 * If we wrap, free up the current structure and
47--
482.12.2
49