DF-5710 / fix.diff
--- a/sys/vfs/smbfs/smbfs_vfsops.c +++ b/sys/vfs/smbfs/smbfs_vfsops.c @@ -167,13 +167,21 @@ bzero(pc, MNAMELEN); *pc++ = '/'; *pc++ = '/'; - pc=index(strncpy(pc, vcp->vc_username, pe - pc - 2), 0); - if (pc < pe-1) { - *(pc++) = '@'; - pc = index(strncpy(pc, vcp->vc_srvname, pe - pc - 2), 0); - if (pc < pe - 1) { - *(pc++) = '/'; - strncpy(pc, ssp->ss_name, pe - pc - 2); + /* + * Require room for at least one payload byte plus the NUL that + * strncpy() is not guaranteed to write: "pe - pc - 2" must never + * be negative, or strncpy() receives (size_t)-1 and copies + * unboundedly (kernel heap corruption past f_mntfromname). + */ + if (pe - pc > 2) { + pc = index(strncpy(pc, vcp->vc_username, pe - pc - 2), 0); + if (pe - pc > 2) { + *(pc++) = '@'; + pc = index(strncpy(pc, vcp->vc_srvname, pe - pc - 2), 0); + if (pe - pc > 2) { + *(pc++) = '/'; + strncpy(pc, ssp->ss_name, pe - pc - 2); + } } } /* protect against invalid mount points */ |