@@ -307,27 +307,35 @@ char const *cf_expand_variables(char const *cf, int lineno,
307307 * it's the property of a section.
308308 */
309309 if (q ) {
310- CONF_SECTION * find = cf_item_to_section (ci );
310+ CONF_SECTION * find ;
311+ char const * f ;
312+ size_t flen ;
311313
312314 if (ci -> type != CONF_ITEM_SECTION ) {
313315 ERROR ("%s[%d]: Can only reference properties of sections" , cf , lineno );
314316 return NULL ;
315317 }
316318
319+ find = cf_item_to_section (ci );
317320 switch (fr_table_value_by_str (conf_property_name , q , CONF_PROPERTY_INVALID )) {
318321 case CONF_PROPERTY_NAME :
319- strcpy ( p , find -> name1 ) ;
322+ f = find -> name1 ;
320323 break ;
321324
322325 case CONF_PROPERTY_INSTANCE :
323- strcpy ( p , find -> name2 ? find -> name2 : find -> name1 ) ;
326+ f = find -> name2 ? find -> name2 : find -> name1 ;
324327 break ;
325328
326329 default :
327330 ERROR ("%s[%d]: Invalid property '%s'" , cf , lineno , q );
328331 return NULL ;
329332 }
330- p += strlen (p );
333+
334+ flen = talloc_array_length (f ) - 1 ;
335+ if ((p + flen ) >= (output + outsize )) goto too_long ;
336+
337+ memcpy (p , f , flen );
338+ p += flen ;
331339 ptr = next ;
332340
333341 } else if (ci -> type == CONF_ITEM_PAIR ) {
@@ -462,6 +470,7 @@ char const *cf_expand_variables(char const *cf, int lineno,
462470
463471 check_eos :
464472 if (p >= (output + outsize )) {
473+ too_long :
465474 ERROR ("%s[%d]: Reference \"%s\" is too long" ,
466475 cf , lineno , input );
467476 return NULL ;
@@ -595,7 +604,10 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F
595604 return -1 ;
596605 }
597606
598- if (fstatat (my_fd , r , & my_file .buf , 0 ) < 0 ) goto error ;
607+ if (fstatat (my_fd , r , & my_file .buf , 0 ) < 0 ) {
608+ if (my_fd != AT_FDCWD ) close (my_fd );
609+ goto error ;
610+ }
599611
600612 file = fr_rb_find (tree , & my_file );
601613
@@ -671,8 +683,8 @@ static int cf_file_open(CONF_SECTION *cs, char const *filename, bool from_dir, F
671683 */
672684void cf_file_check_set_uid_gid (uid_t uid , gid_t gid )
673685{
674- if (uid != 0 ) conf_check_uid = uid ;
675- if (gid != 0 ) conf_check_gid = gid ;
686+ if (uid != ( uid_t ) - 1 ) conf_check_uid = uid ;
687+ if (gid != ( gid_t ) - 1 ) conf_check_gid = gid ;
676688}
677689
678690/** Perform an operation with the effect/group set to conf_check_gid and conf_check_uid
@@ -689,17 +701,17 @@ cf_file_check_err_t cf_file_check_effective(char const *filename,
689701{
690702 int ret ;
691703
692- uid_t euid = (uid_t )- 1 ;
693- gid_t egid = (gid_t )- 1 ;
704+ uid_t euid = (uid_t ) - 1 ;
705+ gid_t egid = (gid_t ) - 1 ;
694706
695- if ((conf_check_gid != (gid_t )- 1 ) && ((egid = getegid ()) != conf_check_gid )) {
707+ if ((conf_check_gid != (gid_t ) - 1 ) && ((egid = getegid ()) != conf_check_gid )) {
696708 if (setegid (conf_check_gid ) < 0 ) {
697709 fr_strerror_printf ("Failed setting effective group ID (%d) for file check: %s" ,
698710 (int ) conf_check_gid , fr_syserror (errno ));
699711 return CF_FILE_OTHER_ERROR ;
700712 }
701713 }
702- if ((conf_check_uid != (uid_t )- 1 ) && ((euid = geteuid ()) != conf_check_uid )) {
714+ if ((conf_check_uid != (uid_t ) - 1 ) && ((euid = geteuid ()) != conf_check_uid )) {
703715 if (seteuid (conf_check_uid ) < 0 ) {
704716 fr_strerror_printf ("Failed setting effective user ID (%d) for file check: %s" ,
705717 (int ) conf_check_uid , fr_syserror (errno ));
@@ -915,10 +927,10 @@ cf_file_check_err_t cf_file_check(CONF_PAIR *cp, bool check_perms)
915927
916928 top = cf_root (cp );
917929 tree = cf_data_value (cf_data_find (top , fr_rb_tree_t , "filename" ));
918- if (!tree ) return false ;
930+ if (!tree ) return CF_FILE_OTHER_ERROR ;
919931
920932 file = talloc (tree , cf_file_t );
921- if (!file ) return false ;
933+ if (!file ) return CF_FILE_OTHER_ERROR ;
922934
923935 file -> filename = talloc_strdup (file , filename ); /* The rest of the code expects this to be talloced */
924936 file -> cs = cf_item_to_section (cf_parent (cp ));
@@ -1236,7 +1248,7 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const *
12361248 */
12371249 {
12381250 char * directory ;
1239- DIR * dir ;
1251+ DIR * dir = NULL ;
12401252 struct dirent * dp ;
12411253 struct stat stat_buf ;
12421254 cf_file_heap_t * h ;
@@ -1258,6 +1270,7 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const *
12581270 frame -> filename , frame -> lineno , value ,
12591271 fr_syserror (errno ));
12601272 error :
1273+ if (dir ) closedir (dir );
12611274 talloc_free (directory );
12621275 return -1 ;
12631276 }
@@ -1318,8 +1331,8 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const *
13181331 * Check for valid characters
13191332 */
13201333 for (p = dp -> d_name ; * p != '\0' ; p ++ ) {
1321- if (isalpha ((uint8_t )* p ) ||
1322- isdigit ((uint8_t )* p ) ||
1334+ if (isalpha ((uint8_t ) * p ) ||
1335+ isdigit ((uint8_t ) * p ) ||
13231336 (* p == '-' ) ||
13241337 (* p == '_' ) ||
13251338 (* p == '.' )) continue ;
@@ -1337,8 +1350,8 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const *
13371350 continue ;
13381351 }
13391352 if ((len > 9 ) && (strncmp (& dp -> d_name [len - 9 ], ".dpkg-old" , 9 ) == 0 )) goto pkg_file ;
1340- if ((len > 7 ) && (strncmp (& dp -> d_name [len - 7 ], ".rpmnew" , 9 ) == 0 )) goto pkg_file ;
1341- if ((len > 8 ) && (strncmp (& dp -> d_name [len - 8 ], ".rpmsave" , 10 ) == 0 )) goto pkg_file ;
1353+ if ((len > 7 ) && (strncmp (& dp -> d_name [len - 7 ], ".rpmnew" , 7 ) == 0 )) goto pkg_file ;
1354+ if ((len > 8 ) && (strncmp (& dp -> d_name [len - 8 ], ".rpmsave" , 8 ) == 0 )) goto pkg_file ;
13421355
13431356 snprintf (stack -> buff [1 ], stack -> bufsize , "%s%s" ,
13441357 frame -> directory , dp -> d_name );
@@ -1362,6 +1375,7 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const *
13621375 h -> heap_id = FR_HEAP_INDEX_INVALID ;
13631376 (void ) fr_heap_insert (& frame -> heap , h );
13641377 }
1378+
13651379 closedir (dir );
13661380 return 1 ;
13671381 }
@@ -1870,9 +1884,10 @@ static CONF_ITEM *process_catch(cf_stack_t *stack)
18701884 continue ;
18711885 }
18721886
1873- if (argc > RLM_MODULE_NUMCODES ) {
1887+ if (argc >= RLM_MODULE_NUMCODES ) {
18741888 ERROR ("%s[%d]: Invalid syntax for 'catch' - too many arguments at'%s'" ,
18751889 frame -> filename , frame -> lineno , ptr );
1890+ talloc_free (name2 );
18761891 return NULL ;
18771892 }
18781893
@@ -2623,11 +2638,11 @@ static int parse_input(cf_stack_t *stack)
26232638 }
26242639
26252640 name2_token = gettoken (& ptr , buff [2 ], stack -> bufsize , false); /* can't be EOL */
2626- if (name1_token == T_INVALID ) {
2641+ if (name2_token == T_INVALID ) {
26272642 return parse_error (stack , ptr2 , fr_strerror ());
26282643 }
26292644
2630- if (name1_token != T_BARE_WORD ) {
2645+ if (name2_token != T_BARE_WORD ) {
26312646 return parse_error (stack , ptr2 , "Unexpected quoted string after section name" );
26322647 }
26332648
0 commit comments