(from mycroft)
SCCS-vsn: sbin/fsck/dir.c 8.5
-static char sccsid[] = "@(#)dir.c 8.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)dir.c 8.5 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
u_char namlen, type;
int spaceleft;
u_char namlen, type;
int spaceleft;
- size = DIRSIZ(!newinofmt, dp);
spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
+ if (dp->d_ino >= maxino ||
+ dp->d_reclen == 0 ||
+ dp->d_reclen > spaceleft ||
+ (dp->d_reclen & 0x3) != 0)
+ return (0);
+ if (dp->d_ino == 0)
+ return (1);
+ size = DIRSIZ(!newinofmt, dp);
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (!newinofmt) {
type = dp->d_namlen;
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (!newinofmt) {
type = dp->d_namlen;
namlen = dp->d_namlen;
type = dp->d_type;
# endif
namlen = dp->d_namlen;
type = dp->d_type;
# endif
- if (dp->d_ino < maxino &&
- dp->d_reclen != 0 &&
- dp->d_reclen <= spaceleft &&
- (dp->d_reclen & 0x3) == 0 &&
- dp->d_reclen >= size &&
- idesc->id_filesize >= size &&
- namlen <= MAXNAMLEN &&
- type <= 15) {
- if (dp->d_ino == 0)
- return (1);
- for (cp = dp->d_name, size = 0; size < namlen; size++)
- if (*cp == 0 || (*cp++ == '/'))
- return (0);
- if (*cp == 0)
- return (1);
- }
- return (0);
+ if (dp->d_reclen < size ||
+ idesc->id_filesize < size ||
+ namlen > MAXNAMLEN ||
+ type > 15)
+ return (0);
+ for (cp = dp->d_name, size = 0; size < namlen; size++)
+ if (*cp == '\0' || (*cp++ == '/'))
+ return (0);
+ if (*cp != '\0')
+ return (0);
+ return (1);