? a.out ? o ? x ? x.c Index: dir.h =================================================================== RCS file: /cvsroot/src/sys/ufs/ufs/dir.h,v retrieving revision 1.25 diff -u -p -u -r1.25 dir.h --- dir.h 1 Sep 2015 06:16:03 -0000 1.25 +++ dir.h 5 May 2019 01:28:31 -0000 @@ -111,8 +111,11 @@ struct direct { * without the d_name field, plus enough space for the name with a terminating * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. */ +#define DIR_ROUNDUP 4 +#define UFS_NAMEROUNDUP(namlen) (((namlen) + DIR_ROUNDUP) & ~(DIR_ROUNDUP - 1)) +#define UFS_NAMEPAD(namlen) (DIR_ROUNDUP - ((namlen) & (DIR_ROUNDUP - 1))) #define UFS_DIRECTSIZ(namlen) \ - ((sizeof(struct direct) - (FFS_MAXNAMLEN+1)) + (((namlen)+1 + 3) &~ 3)) + ((sizeof(struct direct) - (FFS_MAXNAMLEN+1)) + UFS_NAMEROUNDUP(namlen)) #if (BYTE_ORDER == LITTLE_ENDIAN) #define UFS_DIRSIZ(oldfmt, dp, needswap) \ Index: ufs_lookup.c =================================================================== RCS file: /cvsroot/src/sys/ufs/ufs/ufs_lookup.c,v retrieving revision 1.148 diff -u -p -u -r1.148 ufs_lookup.c --- ufs_lookup.c 27 Oct 2017 12:25:15 -0000 1.148 +++ ufs_lookup.c 5 May 2019 01:28:31 -0000 @@ -793,10 +793,15 @@ void ufs_makedirentry(struct inode *ip, struct componentname *cnp, struct direct *newdirp) { + size_t namelen = cnp->cn_namelen; + newdirp->d_ino = ip->i_number; - newdirp->d_namlen = cnp->cn_namelen; - memcpy(newdirp->d_name, cnp->cn_nameptr, (size_t)cnp->cn_namelen); - newdirp->d_name[cnp->cn_namelen] = '\0'; + newdirp->d_namlen = namelen; + memcpy(newdirp->d_name, cnp->cn_nameptr, namelen); + + /* Zero out padding */ + memset(&newdirp->d_name[namelen], 0, UFS_NAMEPAD(namelen)); + if (FSFMT(ITOV(ip))) newdirp->d_type = 0; else