aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2023-03-11 13:39:24 -0500
committerBrian Behlendorf <[email protected]>2023-03-14 15:25:55 -0700
commitdbfc622345f95e09ce36cbecf70715b7adcad661 (patch)
tree01e20b462be771708504fbc2054a85034e4113c5 /include
parentd1807f168edd09ca26a5a0c6b570686b982808ad (diff)
nvpair: Use flexible array member for nvpair name strings
Coverity reported possible out-of-bounds reads from doing `((char *)(nvp) + sizeof (nvpair_t))` to get the nvpair name string. These were initially marked as false positives, but since we are now using C99 flexible array members elsewhere, we could use them here too as cleanup to make the code easier to understand. Reviewed-by: Tino Reichardt <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Richard Yao <[email protected]> Reported-by: Coverity (CID-977165) Reported-by: Coverity (CID-1524109) Reported-by: Coverity (CID-1524642) Closes #14612
Diffstat (limited to 'include')
-rw-r--r--include/sys/nvpair.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/sys/nvpair.h b/include/sys/nvpair.h
index 33eda9be1..2dbd9e3ea 100644
--- a/include/sys/nvpair.h
+++ b/include/sys/nvpair.h
@@ -76,7 +76,7 @@ typedef struct nvpair {
int16_t nvp_reserve; /* not used */
int32_t nvp_value_elem; /* number of elements for array types */
data_type_t nvp_type; /* type of value */
- /* name string */
+ char nvp_name[]; /* name string */
/* aligned ptr array for string arrays */
/* aligned array of data for value */
} nvpair_t;
@@ -109,7 +109,7 @@ typedef struct nvlist {
#define NV_ALIGN4(x) (((x) + 3) & ~3)
#define NVP_SIZE(nvp) ((nvp)->nvp_size)
-#define NVP_NAME(nvp) ((char *)(nvp) + sizeof (nvpair_t))
+#define NVP_NAME(nvp) ((nvp)->nvp_name)
#define NVP_TYPE(nvp) ((nvp)->nvp_type)
#define NVP_NELEM(nvp) ((nvp)->nvp_value_elem)
#define NVP_VALUE(nvp) ((char *)(nvp) + NV_ALIGN(sizeof (nvpair_t) \