diff options
author | Jim Meyering <jim@meyering.net> | 2004-06-08 13:31:43 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-06-08 13:31:43 +0000 |
commit | 12357df452799138a4e726b5e782cdc87f5fa46a (patch) | |
tree | 03e4776db72ad6581cedfa8521bfd3cdb634a169 | |
parent | 2eba29a31299cd982eee2a7a7b05406d08edd397 (diff) | |
download | coreutils-12357df452799138a4e726b5e782cdc87f5fa46a.tar.xz |
(fts_stat, fts_alloc): Always allocate and use a struct
stat, even if the user isn't interested in the results.
This prevents a core dump in cycle_check when FTS_NOSTAT is set.
-rw-r--r-- | lib/fts.c | 20 |
1 files changed, 6 insertions, 14 deletions
@@ -1136,19 +1136,14 @@ fts_stat(sp, p, follow) register FTSENT *p; int follow; { - struct stat *sbp, sb; + struct stat *sbp = p->fts_statp; int saved_errno; - /* If user needs stat info, stat buffer already allocated. */ - sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; - #if defined FTS_WHITEOUT && 0 /* check for whiteout */ if (p->fts_flags & FTS_ISW) { - if (sbp != &sb) { - memset(sbp, '\0', sizeof (*sbp)); - sbp->st_mode = S_IFWHT; - } + memset(sbp, '\0', sizeof (*sbp)); + sbp->st_mode = S_IFWHT; return (FTS_W); } #endif @@ -1247,16 +1242,14 @@ fts_alloc(sp, name, namelen) size_t len; /* - * The file name is a variable length array and no stat structure is - * necessary if the user has set the nostat bit. Allocate the FTSENT + * The file name is a variable length array. Allocate the FTSENT * structure, the file name and the stat structure in one chunk, but * be careful that the stat structure is reasonably aligned. Since the * fts_name field is declared to be of size 1, the fts_name pointer is * namelen + 2 before the first possible address of the stat structure. */ len = sizeof(FTSENT) + namelen; - if (!ISSET(FTS_NOSTAT)) - len += sizeof(struct stat) + ALIGNBYTES; + len += sizeof(struct stat) + ALIGNBYTES; if ((p = malloc(len)) == NULL) return (NULL); @@ -1264,8 +1257,7 @@ fts_alloc(sp, name, namelen) memmove(p->fts_name, name, namelen); p->fts_name[namelen] = '\0'; - if (!ISSET(FTS_NOSTAT)) - p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); + p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); p->fts_namelen = namelen; p->fts_path = sp->fts_path; p->fts_errno = 0; |