From ccc92611b1bd0a78a72f553472a91ef1e83b06c5 Mon Sep 17 00:00:00 2001 From: cao Date: Sat, 8 Oct 2016 04:19:43 +0800 Subject: Fix coverity defects: CID 147565-147567 coverity scan CID:147567, Type:dereference null return value coverity scan CID:147566, Type:dereference null return value coverity scan CID:147565, Type:dereference null return value Reviewed by: Richard Laager Reviewed-by: Brian Behlendorf Signed-off-by: cao.xuewen Closes #5166 --- lib/libzpool/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/libzpool/util.c b/lib/libzpool/util.c index 7a0748c03..bc3bcbe78 100644 --- a/lib/libzpool/util.c +++ b/lib/libzpool/util.c @@ -123,13 +123,15 @@ show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent) for (c = 0; c < children; c++) { nvlist_t *cnv = child[c]; - char *cname, *tname; + char *cname = NULL, *tname; uint64_t np; + int len; if (nvlist_lookup_string(cnv, ZPOOL_CONFIG_PATH, &cname) && nvlist_lookup_string(cnv, ZPOOL_CONFIG_TYPE, &cname)) cname = ""; - tname = calloc(1, strlen(cname) + 2); - (void) strcpy(tname, cname); + len = strlen(cname) + 2; + tname = umem_zalloc(len, UMEM_NOFAIL); + (void) strlcpy(tname, cname, len); if (nvlist_lookup_uint64(cnv, ZPOOL_CONFIG_NPARITY, &np) == 0) tname[strlen(tname)] = '0' + np; show_vdev_stats(tname, ctype, cnv, indent + 2); -- cgit v1.2.3