diff options
author | George Melikov <[email protected]> | 2017-01-27 22:10:10 +0300 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-01-27 11:10:10 -0800 |
commit | 687e612f9a56763d82c78ed75656896ce9cace17 (patch) | |
tree | 9bf0d6679c805e00d0dd437d535bdcecd932e883 /lib/libzfs | |
parent | 933ec999511f3d29de005bfa8966ae007b161c0f (diff) |
Add realloc() success check in zpool_history_unpack()
Correctly handle the unlikely case where the memory buffer cannot be resized.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Giuseppe Di Natale <[email protected]>
Signed-off-by: George Melikov <[email protected]>
Closes #5575
Diffstat (limited to 'lib/libzfs')
-rw-r--r-- | lib/libzfs/libzfs_pool.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index afc665f49..67db13401 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -3758,6 +3758,7 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover, uint64_t reclen; nvlist_t *nv; int i; + void *tmp; while (bytes_read > sizeof (reclen)) { @@ -3777,8 +3778,14 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover, /* add record to nvlist array */ (*numrecords)++; if (ISP2(*numrecords + 1)) { - *records = realloc(*records, + tmp = realloc(*records, *numrecords * 2 * sizeof (nvlist_t *)); + if (tmp == NULL) { + nvlist_free(nv); + (*numrecords)--; + return (ENOMEM); + } + *records = tmp; } (*records)[*numrecords - 1] = nv; } |