Use strlcpy to NULL-terminate error message even if user provided a short

buffer.
This commit is contained in:
David Xu 2012-12-28 02:43:33 +00:00
parent 0c093a7055
commit 9d4bf0db7c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=244760

View File

@ -559,7 +559,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions)
if (error || fstype[fstypelen - 1] != '\0') { if (error || fstype[fstypelen - 1] != '\0') {
error = EINVAL; error = EINVAL;
if (errmsg != NULL) if (errmsg != NULL)
strncpy(errmsg, "Invalid fstype", errmsg_len); strlcpy(errmsg, "Invalid fstype", errmsg_len);
goto bail; goto bail;
} }
fspathlen = 0; fspathlen = 0;
@ -567,7 +567,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions)
if (error || fspath[fspathlen - 1] != '\0') { if (error || fspath[fspathlen - 1] != '\0') {
error = EINVAL; error = EINVAL;
if (errmsg != NULL) if (errmsg != NULL)
strncpy(errmsg, "Invalid fspath", errmsg_len); strlcpy(errmsg, "Invalid fspath", errmsg_len);
goto bail; goto bail;
} }
@ -1447,7 +1447,7 @@ vfs_filteropt(struct vfsoptlist *opts, const char **legal)
if (ret != 0) { if (ret != 0) {
TAILQ_FOREACH(opt, opts, link) { TAILQ_FOREACH(opt, opts, link) {
if (strcmp(opt->name, "errmsg") == 0) { if (strcmp(opt->name, "errmsg") == 0) {
strncpy((char *)opt->value, errmsg, opt->len); strlcpy((char *)opt->value, errmsg, opt->len);
break; break;
} }
} }