diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2018-08-14 18:11:06 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2018-08-14 18:11:06 +0000 |
commit | cc4deabc28a0f094e9523c3e88ca2631a80e39e4 (patch) | |
tree | 217a4cc883992c727c6e892810665263211d8fb6 /lib | |
parent | dea77ea6fc17930104a7cf5c04b7aa6acc4a33fb (diff) | |
download | src-cc4deabc28a0f094e9523c3e88ca2631a80e39e4.tar.gz src-cc4deabc28a0f094e9523c3e88ca2631a80e39e4.zip |
Notes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libbe/be.c | 45 | ||||
-rw-r--r-- | lib/libbe/be_access.c | 5 | ||||
-rw-r--r-- | lib/libbe/be_impl.h | 6 |
3 files changed, 27 insertions, 29 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c index bc82fff6ec53..1061b9c770d7 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -64,10 +64,13 @@ be_locate_rootfs(zfs_handle_t *chkds, void *data) if (lbh == NULL) return (1); + mntpoint = NULL; if (zfs_is_mounted(chkds, &mntpoint) && strcmp(mntpoint, "/") == 0) { - strncpy(lbh->rootfs, zfs_get_name(chkds), BE_MAXPATHLEN); + strlcpy(lbh->rootfs, zfs_get_name(chkds), BE_MAXPATHLEN + 1); + free(mntpoint); return (1); - } + } else if(mntpoint != NULL) + free(mntpoint); return (0); } @@ -120,8 +123,8 @@ libbe_init(void) /* Remove leading 'zfs:' if present, otherwise use value as-is */ if (strcmp(lbh->root, "zfs:") == 0) - strncpy(lbh->root, strchr(lbh->root, ':') + sizeof(char), - BE_MAXPATHLEN); + strlcpy(lbh->root, strchr(lbh->root, ':') + sizeof(char), + BE_MAXPATHLEN + 1); if ((pos = strchr(lbh->root, '/')) == NULL) goto err; @@ -160,8 +163,6 @@ err: libzfs_fini(lbh->lzh); free(lbh); } - if (rootds != NULL) - zfs_close(rootds); free(poolname); return (NULL); } @@ -397,20 +398,16 @@ be_deep_clone(zfs_handle_t *ds, void *data) ZFS_TYPE_FILESYSTEM) == ZPROP_INVAL) return (-1); - if ((err = zfs_clone(snap_hdl, be_path, props)) != 0) { - switch (err) { - case EZFS_SUCCESS: - err = BE_ERR_SUCCESS; - break; - default: - err = BE_ERR_ZFSCLONE; - break; - } - } + if ((err = zfs_clone(snap_hdl, be_path, props)) != 0) + err = BE_ERR_ZFSCLONE; nvlist_free(props); zfs_close(snap_hdl); + /* Failed to clone */ + if (err != BE_ERR_SUCCESS) + return (set_error(isdc->lbh, err)); + sdc.lbh = isdc->lbh; sdc.bename = NULL; sdc.snapname = isdc->snapname; @@ -451,14 +448,13 @@ be_create_from_existing_snap(libbe_handle_t *lbh, const char *name, else bename++; - if ((parentname = strdup(snap_path)) == NULL) { - err = BE_ERR_UNKNOWN; - return (set_error(lbh, err)); - } + if ((parentname = strdup(snap_path)) == NULL) + return (set_error(lbh, BE_ERR_UNKNOWN)); + snapname = strchr(parentname, '@'); if (snapname == NULL) { - err = BE_ERR_UNKNOWN; - return (set_error(lbh, err)); + free(parentname); + return (set_error(lbh, BE_ERR_UNKNOWN)); } *snapname = '\0'; snapname++; @@ -471,6 +467,7 @@ be_create_from_existing_snap(libbe_handle_t *lbh, const char *name, parent_hdl = zfs_open(lbh->lzh, parentname, ZFS_TYPE_DATASET); err = be_deep_clone(parent_hdl, &sdc); + free(parentname); return (set_error(lbh, err)); } @@ -502,7 +499,7 @@ int be_validate_snap(libbe_handle_t *lbh, const char *snap_name) { zfs_handle_t *zfs_hdl; - char buf[BE_MAXPATHLEN]; + char buf[BE_MAXPATHLEN + 1]; char *delim_pos; int err = BE_ERR_SUCCESS; @@ -513,7 +510,7 @@ be_validate_snap(libbe_handle_t *lbh, const char *snap_name) ZFS_TYPE_SNAPSHOT)) return (BE_ERR_NOENT); - strncpy(buf, snap_name, BE_MAXPATHLEN); + strlcpy(buf, snap_name, BE_MAXPATHLEN + 1); /* Find the base filesystem of the snapshot */ if ((delim_pos = strchr(buf, '@')) == NULL) diff --git a/lib/libbe/be_access.c b/lib/libbe/be_access.c index e1c4be5fbb3d..892f5755f079 100644 --- a/lib/libbe/be_access.c +++ b/lib/libbe/be_access.c @@ -51,8 +51,10 @@ be_mountcheck_cb(zfs_handle_t *zfs_hdl, void *data) return (0); if (strcmp(mountpoint, info->path) == 0) { info->name = strdup(zfs_get_name(zfs_hdl)); + free(mountpoint); return (1); } + free(mountpoint); return (0); } @@ -106,7 +108,6 @@ be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags, { char be[BE_MAXPATHLEN]; char mnt_temp[BE_MAXPATHLEN]; - char *path; int mntflags; int err; @@ -116,7 +117,7 @@ be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags, if (!be_exists(lbh, bootenv)) return (set_error(lbh, BE_ERR_NOENT)); - if (is_mounted(lbh->lzh, be, &path)) + if (is_mounted(lbh->lzh, be, NULL)) return (set_error(lbh, BE_ERR_MOUNTED)); mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0; diff --git a/lib/libbe/be_impl.h b/lib/libbe/be_impl.h index 99c783a1a646..be6673d78c48 100644 --- a/lib/libbe/be_impl.h +++ b/lib/libbe/be_impl.h @@ -38,9 +38,9 @@ struct libbe_handle { libzfs_handle_t *lzh; zpool_handle_t *active_phandle; - char root[BE_MAXPATHLEN]; - char rootfs[BE_MAXPATHLEN]; - char bootfs[BE_MAXPATHLEN]; + char root[BE_MAXPATHLEN + 1]; + char rootfs[BE_MAXPATHLEN + 1]; + char bootfs[BE_MAXPATHLEN + 1]; be_error_t error; bool print_on_err; }; |