1717
1818const char * config_b2sum = CONFIG_B2SUM_SIGNATURE CONFIG_B2SUM_EMPTY ;
1919
20- static bool config_get_entry_name ( char * ret , size_t index , size_t limit );
20+ static char * config_get_entry_name ( size_t index );
2121static char * config_get_entry (size_t * size , size_t index );
2222
2323#define SEPARATOR '\n'
@@ -252,23 +252,30 @@ bool init_config_smbios(void) {
252252#define DIRECT_CHILD 0
253253#define INDIRECT_CHILD 1
254254
255- static int is_child (char * buf , size_t limit ,
256- size_t current_depth , size_t index ) {
257- if (! config_get_entry_name ( buf , index , limit ) )
255+ static int is_child (size_t current_depth , size_t index ) {
256+ char * buf = config_get_entry_name ( index );
257+ if (buf == NULL )
258258 return NOT_CHILD ;
259- if (strlen (buf ) < current_depth + 1 )
260- return NOT_CHILD ;
261- for (size_t j = 0 ; j < current_depth ; j ++ )
262- if (buf [j ] != '/' )
263- return NOT_CHILD ;
264- if (buf [current_depth ] == '/' )
265- return INDIRECT_CHILD ;
266- return DIRECT_CHILD ;
259+ int ret ;
260+ if (strlen (buf ) < current_depth + 1 ) {
261+ ret = NOT_CHILD ;
262+ } else {
263+ ret = DIRECT_CHILD ;
264+ for (size_t j = 0 ; j < current_depth ; j ++ ) {
265+ if (buf [j ] != '/' ) {
266+ ret = NOT_CHILD ;
267+ break ;
268+ }
269+ }
270+ if (ret == DIRECT_CHILD && buf [current_depth ] == '/' )
271+ ret = INDIRECT_CHILD ;
272+ }
273+ pmm_free (buf , strlen (buf ) + 1 );
274+ return ret ;
267275}
268276
269- static bool is_directory (char * buf , size_t limit ,
270- size_t current_depth , size_t index ) {
271- switch (is_child (buf , limit , current_depth + 1 , index + 1 )) {
277+ static bool is_directory (size_t current_depth , size_t index ) {
278+ switch (is_child (current_depth + 1 , index + 1 )) {
272279 default :
273280 case NOT_CHILD :
274281 return false;
@@ -285,9 +292,7 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent,
285292 struct menu_entry * root = NULL , * prev = NULL ;
286293
287294 for (size_t i = index ; ; i ++ ) {
288- static char name [64 ];
289-
290- switch (is_child (name , 64 , current_depth , i )) {
295+ switch (is_child (current_depth , i )) {
291296 case NOT_CHILD :
292297 return root ;
293298 case INDIRECT_CHILD :
@@ -301,7 +306,7 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent,
301306 if (root == NULL )
302307 root = entry ;
303308
304- config_get_entry_name ( name , i , 64 );
309+ char * name = config_get_entry_name ( i );
305310
306311 bool default_expanded = name [current_depth ] == '+' ;
307312
@@ -310,12 +315,8 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent,
310315 n ++ ;
311316 }
312317
313- size_t n_len = strlen (n );
314- if (n_len >= sizeof (entry -> name )) {
315- n_len = sizeof (entry -> name ) - 1 ;
316- }
317- memcpy (entry -> name , n , n_len );
318- entry -> name [n_len ] = 0 ;
318+ entry -> name = strdup (n );
319+ pmm_free (name , strlen (name ) + 1 );
319320 entry -> parent = parent ;
320321
321322 size_t entry_size ;
@@ -324,7 +325,7 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent,
324325 memcpy (entry -> body , config_entry , entry_size );
325326 entry -> body [entry_size ] = 0 ;
326327
327- if (is_directory (name , 64 , current_depth , i )) {
328+ if (is_directory (current_depth , i )) {
328329 entry -> sub = create_menu_tree (entry , current_depth + 1 , i + 1 );
329330 entry -> expanded = default_expanded ;
330331 }
@@ -604,16 +605,16 @@ int init_config(size_t config_size) {
604605 return 0 ;
605606}
606607
607- static bool config_get_entry_name ( char * ret , size_t index , size_t limit ) {
608+ static char * config_get_entry_name ( size_t index ) {
608609 if (!config_ready )
609- return false ;
610+ return NULL ;
610611
611612 char * p = config_addr ;
612613
613614 for (size_t i = 0 ; i <= index ; i ++ ) {
614615 while (* p != '/' ) {
615616 if (!* p )
616- return false ;
617+ return NULL ;
617618 p ++ ;
618619 }
619620 p ++ ;
@@ -623,15 +624,15 @@ static bool config_get_entry_name(char *ret, size_t index, size_t limit) {
623624
624625 p -- ;
625626
626- size_t i ;
627- for (i = 0 ; i < (limit - 1 ); i ++ ) {
628- if (p [i ] == SEPARATOR )
629- break ;
630- ret [i ] = p [i ];
627+ size_t len = 0 ;
628+ while (p [len ] != SEPARATOR ) {
629+ len ++ ;
631630 }
632631
633- ret [i ] = 0 ;
634- return true;
632+ char * ret = ext_mem_alloc (len + 1 );
633+ memcpy (ret , p , len );
634+ ret [len ] = 0 ;
635+ return ret ;
635636}
636637
637638static char * config_get_entry (size_t * size , size_t index ) {
0 commit comments