3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
+ #undef _POSIX_C_SOURCE
7
+ #define _POSIX_C_SOURCE 200809L /* for strnlen() */
8
+
6
9
#include <errno.h>
7
10
#include <string.h>
8
11
@@ -169,12 +172,13 @@ static int settings_zms_load_subtree(struct settings_store *cs, const struct set
169
172
{
170
173
struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
171
174
struct settings_zms_read_fn_arg read_fn_arg ;
172
- char name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
175
+ char name [SETTINGS_FULL_NAME_LEN ];
173
176
ssize_t rc1 ;
174
177
ssize_t rc2 ;
175
178
uint32_t name_hash ;
176
179
177
- name_hash = sys_hash32 (arg -> subtree , strlen (arg -> subtree )) & ZMS_HASH_MASK ;
180
+ name_hash = sys_hash32 (arg -> subtree , strnlen (arg -> subtree , SETTINGS_FULL_NAME_LEN )) &
181
+ ZMS_HASH_MASK ;
178
182
for (int i = 0 ; i <= cf -> hash_collision_num ; i ++ ) {
179
183
name_hash = ZMS_UPDATE_COLLISION_NUM (name_hash , i );
180
184
/* Get the name entry from ZMS */
@@ -214,7 +218,7 @@ static ssize_t settings_zms_load_one(struct settings_store *cs, const char *name
214
218
size_t buf_len )
215
219
{
216
220
struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
217
- char r_name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
221
+ char r_name [SETTINGS_FULL_NAME_LEN ];
218
222
ssize_t rc = 0 ;
219
223
uint32_t name_hash ;
220
224
uint32_t value_id ;
@@ -224,7 +228,7 @@ static ssize_t settings_zms_load_one(struct settings_store *cs, const char *name
224
228
return - EINVAL ;
225
229
}
226
230
227
- name_hash = sys_hash32 (name , strlen (name )) & ZMS_HASH_MASK ;
231
+ name_hash = sys_hash32 (name , strnlen (name , SETTINGS_FULL_NAME_LEN )) & ZMS_HASH_MASK ;
228
232
for (int i = 0 ; i <= cf -> hash_collision_num ; i ++ ) {
229
233
name_hash = ZMS_UPDATE_COLLISION_NUM (name_hash , i );
230
234
/* Get the name entry from ZMS */
@@ -259,7 +263,7 @@ static int settings_zms_load(struct settings_store *cs, const struct settings_lo
259
263
struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
260
264
struct settings_zms_read_fn_arg read_fn_arg ;
261
265
struct settings_hash_linked_list settings_element ;
262
- char name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
266
+ char name [SETTINGS_FULL_NAME_LEN ];
263
267
ssize_t rc1 ;
264
268
ssize_t rc2 ;
265
269
uint32_t ll_hash_id ;
@@ -380,7 +384,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
380
384
{
381
385
struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
382
386
struct settings_hash_linked_list settings_element ;
383
- char rdname [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
387
+ char rdname [SETTINGS_FULL_NAME_LEN ];
384
388
uint32_t name_hash ;
385
389
uint32_t collision_num = 0 ;
386
390
bool delete ;
@@ -396,7 +400,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
396
400
/* Find out if we are doing a delete */
397
401
delete = ((value == NULL ) || (val_len == 0 ));
398
402
399
- name_hash = sys_hash32 (name , strlen (name )) & ZMS_HASH_MASK ;
403
+ name_hash = sys_hash32 (name , strnlen (name , SETTINGS_FULL_NAME_LEN )) & ZMS_HASH_MASK ;
400
404
/* MSB is always 1 */
401
405
name_hash |= BIT (31 );
402
406
@@ -523,7 +527,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
523
527
no_ll_update :
524
528
#endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
525
529
/* Now let's write the name */
526
- rc = zms_write (& cf -> cf_zms , name_hash , name , strlen (name ));
530
+ rc = zms_write (& cf -> cf_zms , name_hash , name , strnlen (name , SETTINGS_FULL_NAME_LEN ));
527
531
if (rc < 0 ) {
528
532
return rc ;
529
533
}
@@ -534,7 +538,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
534
538
static ssize_t settings_zms_get_val_len (struct settings_store * cs , const char * name )
535
539
{
536
540
struct settings_zms * cf = CONTAINER_OF (cs , struct settings_zms , cf_store );
537
- char r_name [SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1 ];
541
+ char r_name [SETTINGS_FULL_NAME_LEN ];
538
542
ssize_t rc = 0 ;
539
543
uint32_t name_hash ;
540
544
@@ -543,7 +547,7 @@ static ssize_t settings_zms_get_val_len(struct settings_store *cs, const char *n
543
547
return - EINVAL ;
544
548
}
545
549
546
- name_hash = sys_hash32 (name , strlen (name )) & ZMS_HASH_MASK ;
550
+ name_hash = sys_hash32 (name , strnlen (name , SETTINGS_FULL_NAME_LEN )) & ZMS_HASH_MASK ;
547
551
for (int i = 0 ; i <= cf -> hash_collision_num ; i ++ ) {
548
552
name_hash = ZMS_UPDATE_COLLISION_NUM (name_hash , i );
549
553
/* Get the name entry from ZMS */
0 commit comments