summaryrefslogtreecommitdiffstats
path: root/module/zfs/dbuf_stats.c
diff options
context:
space:
mode:
authorNed Bass <[email protected]>2014-11-06 18:18:32 -0800
committerBrian Behlendorf <[email protected]>2014-11-17 15:28:59 -0800
commit7b2d78a046aa4695d434478a439a9438521d73af (patch)
tree1176ac3d83fc4187a5893786f1cae8b6b30aa25e /module/zfs/dbuf_stats.c
parent89b1cd6581528c576bd4ff7f713f671b23b051b5 (diff)
Fix improper null-byte termination handling
Fix a few cases where null-byte termination of strings was done unnecessarily or incorrectly. - The snprintf() function always produces a null-byte terminated string for non-negative return values, so it is not necessary to write out a null-byte as a separate step. - Also, it is unsafe to use the return value of snprintf() as an offset for placing a null-byte, because if the output was truncated the return value is the number of bytes that _would_ have been written had enough space been available. Therefore the return value may index beyond the array boundaries. - Finally, snprintf() accounts for the null-byte when limiting its output size, so there is no need to pass it a size parameter that is one less than the buffer size. Signed-off-by: Ned Bass <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #2875
Diffstat (limited to 'module/zfs/dbuf_stats.c')
-rw-r--r--module/zfs/dbuf_stats.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/module/zfs/dbuf_stats.c b/module/zfs/dbuf_stats.c
index 0cad9efdd..0e4c18ed7 100644
--- a/module/zfs/dbuf_stats.c
+++ b/module/zfs/dbuf_stats.c
@@ -45,7 +45,7 @@ static dbuf_stats_t dbuf_stats_hash_table;
static int
dbuf_stats_hash_table_headers(char *buf, size_t size)
{
- size = snprintf(buf, size - 1,
+ (void) snprintf(buf, size,
"%-88s | %-124s | %s\n"
"%-16s %-8s %-8s %-8s %-8s %-8s %-8s %-5s %-5s %5s | "
"%-5s %-5s %-6s %-8s %-6s %-8s %-12s "
@@ -57,7 +57,6 @@ dbuf_stats_hash_table_headers(char *buf, size_t size)
"mru", "gmru", "mfu", "gmfu", "l2", "l2_dattr", "l2_asize",
"l2_comp", "aholds", "dtype", "btype", "data_bs", "meta_bs",
"bsize", "lvls", "dholds", "blocks", "dsize");
- buf[size] = '\0';
return (0);
}
@@ -75,7 +74,7 @@ __dbuf_stats_hash_table_data(char *buf, size_t size, dmu_buf_impl_t *db)
if (dn)
__dmu_object_info_from_dnode(dn, &doi);
- size = snprintf(buf, size - 1,
+ (void) snprintf(buf, size,
"%-16s %-8llu %-8lld %-8lld %-8lld %-8llu %-8llu %-5d %-5d %-5lu | "
"%-5d %-5d %-6lld 0x%-6x %-6lu %-8llu %-12llu "
"%-6lu %-6lu %-6lu %-6lu %-6lu %-8llu %-8llu %-8d %-5lu | "
@@ -118,7 +117,6 @@ __dbuf_stats_hash_table_data(char *buf, size_t size, dmu_buf_impl_t *db)
(ulong_t)refcount_count(&dn->dn_holds),
(u_longlong_t)doi.doi_fill_count,
(u_longlong_t)doi.doi_max_offset);
- buf[size] = '\0';
return (size);
}