33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6+ #define _POSIX_C_SOURCE 200809L /* for strnlen() */
7+
68#include <errno.h>
79#include <string.h>
810
@@ -218,13 +220,14 @@ static int settings_zms_load_subtree(struct settings_store *cs, const struct set
218220{
219221 struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
220222 struct settings_zms_read_fn_arg read_fn_arg ;
221- char name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
223+ char name [SETTINGS_FULL_NAME_LEN ];
222224 ssize_t rc1 ;
223225 ssize_t rc2 ;
224226 uint32_t name_hash ;
225227 int ret = 0 ;
226228
227- name_hash = sys_hash32 (arg -> subtree , strlen (arg -> subtree )) & ZMS_HASH_MASK ;
229+ name_hash = sys_hash32 (arg -> subtree , strnlen (arg -> subtree , SETTINGS_FULL_NAME_LEN )) &
230+ ZMS_HASH_MASK ;
228231 for (int i = 0 ; i <= cf -> hash_collision_num ; i ++ ) {
229232 name_hash = ZMS_UPDATE_COLLISION_NUM (name_hash , i );
230233 /* Get the name entry from ZMS */
@@ -249,8 +252,8 @@ static int settings_zms_load_subtree(struct settings_store *cs, const struct set
249252 read_fn_arg .fs = & cf -> cf_zms ;
250253 read_fn_arg .id = ZMS_NAME_ID_FROM_HASH (name_hash ) + ZMS_DATA_ID_OFFSET ;
251254
252- ret = settings_call_set_handler (arg -> subtree , rc2 , settings_zms_read_fn , & read_fn_arg ,
253- (void * )arg );
255+ ret = settings_call_set_handler (arg -> subtree , rc2 , settings_zms_read_fn ,
256+ & read_fn_arg , (void * )arg );
254257 /* We should return here as there are no need to look for the next
255258 * hash collision */
256259 return ret ;
@@ -264,7 +267,7 @@ static ssize_t settings_zms_load_one(struct settings_store *cs, const char *name
264267 size_t buf_len )
265268{
266269 struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
267- char r_name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
270+ char r_name [SETTINGS_FULL_NAME_LEN ];
268271 ssize_t rc = 0 ;
269272 uint32_t name_hash ;
270273
@@ -273,7 +276,7 @@ static ssize_t settings_zms_load_one(struct settings_store *cs, const char *name
273276 return - EINVAL ;
274277 }
275278
276- name_hash = sys_hash32 (name , strlen (name )) & ZMS_HASH_MASK ;
279+ name_hash = sys_hash32 (name , strnlen (name , SETTINGS_FULL_NAME_LEN )) & ZMS_HASH_MASK ;
277280 for (int i = 0 ; i <= cf -> hash_collision_num ; i ++ ) {
278281 name_hash = ZMS_UPDATE_COLLISION_NUM (name_hash , i );
279282 /* Get the name entry from ZMS */
@@ -306,7 +309,7 @@ static int settings_zms_load(struct settings_store *cs, const struct settings_lo
306309 struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
307310 struct settings_zms_read_fn_arg read_fn_arg ;
308311 struct settings_hash_linked_list settings_element ;
309- char name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
312+ char name [SETTINGS_FULL_NAME_LEN ];
310313 ssize_t rc1 ;
311314 ssize_t rc2 ;
312315 uint32_t ll_hash_id ;
@@ -431,7 +434,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
431434{
432435 struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
433436 struct settings_hash_linked_list settings_element ;
434- char rdname [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
437+ char rdname [SETTINGS_FULL_NAME_LEN ];
435438 uint32_t name_hash ;
436439 uint32_t collision_num = 0 ;
437440 bool delete ;
@@ -449,7 +452,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
449452 /* Find out if we are doing a delete */
450453 delete = ((value == NULL ) || (val_len == 0 ));
451454
452- name_hash = sys_hash32 (name , strlen (name )) & ZMS_HASH_MASK ;
455+ name_hash = sys_hash32 (name , strnlen (name , SETTINGS_FULL_NAME_LEN )) & ZMS_HASH_MASK ;
453456 /* MSB is always 1 */
454457 name_hash |= BIT (31 );
455458
@@ -603,7 +606,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
603606no_ll_update :
604607#endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
605608 /* Now let's write the name */
606- rc = zms_write (& cf -> cf_zms , name_hash , name , strlen (name ));
609+ rc = zms_write (& cf -> cf_zms , name_hash , name , strnlen (name , SETTINGS_FULL_NAME_LEN ));
607610 if (rc < 0 ) {
608611 return rc ;
609612 }
@@ -624,7 +627,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
624627static ssize_t settings_zms_get_val_len (struct settings_store * cs , const char * name )
625628{
626629 struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
627- char r_name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
630+ char r_name [SETTINGS_FULL_NAME_LEN ];
628631 ssize_t rc = 0 ;
629632 uint32_t name_hash ;
630633
@@ -633,7 +636,7 @@ static ssize_t settings_zms_get_val_len(struct settings_store *cs, const char *n
633636 return - EINVAL ;
634637 }
635638
636- name_hash = sys_hash32 (name , strlen (name )) & ZMS_HASH_MASK ;
639+ name_hash = sys_hash32 (name , strnlen (name , SETTINGS_FULL_NAME_LEN )) & ZMS_HASH_MASK ;
637640 for (int i = 0 ; i <= cf -> hash_collision_num ; i ++ ) {
638641 name_hash = ZMS_UPDATE_COLLISION_NUM (name_hash , i );
639642 /* Get the name entry from ZMS */
0 commit comments