From 5c8b941e03e3bc6fef14e2824bfe6783828fe223 Mon Sep 17 00:00:00 2001 From: rarul Date: Thu, 9 May 2024 03:20:58 +0900 Subject: [PATCH] change usage for variable array UBSAN detected array-index-out-of-bounds in: - px4_drv/0.2.1/build/driver/ptx_chrdev.c:817:45 - px4_drv/0.2.1/build/driver/px4_device.c:1354:49 - px4_drv/0.2.1/build/driver/px4_device.c:1355:48 To avoid the detection, we use "[]" instead of "[1]". --- driver/ptx_chrdev.c | 2 +- driver/ptx_chrdev.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/driver/ptx_chrdev.c b/driver/ptx_chrdev.c index 7af7269..b614651 100644 --- a/driver/ptx_chrdev.c +++ b/driver/ptx_chrdev.c @@ -806,7 +806,7 @@ int ptx_chrdev_context_add_group(struct ptx_chrdev_context *chrdev_ctx, base, num, PTX_CHRDEV_MINOR_IN_USE); - group = kzalloc(sizeof(*group) + (sizeof(group->chrdev[0]) * (num - 1)), + group = kzalloc(sizeof(*group) + (sizeof(group->chrdev[0]) * (num)), GFP_KERNEL); if (!group) { ret = -ENOMEM; diff --git a/driver/ptx_chrdev.h b/driver/ptx_chrdev.h index 3a159f5..bd64e9c 100644 --- a/driver/ptx_chrdev.h +++ b/driver/ptx_chrdev.h @@ -100,7 +100,7 @@ struct ptx_chrdev_group { void (*owner_kref_release)(struct kref *); unsigned int minor_base; unsigned int chrdev_num; - struct ptx_chrdev chrdev[1]; + struct ptx_chrdev chrdev[]; }; #define PTX_CHRDEV_MINOR_FREE 0 -- 2.43.0