Skip to content

Commit 1cdcb70

Browse files
committed
catch corner cases in parsing files
1 parent 1f73b44 commit 1cdcb70

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/lib/server/cf_file.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ cf_file_check_err_t cf_file_check_effective(char const *filename,
715715
if (seteuid(conf_check_uid) < 0) {
716716
fr_strerror_printf("Failed setting effective user ID (%d) for file check: %s",
717717
(int) conf_check_uid, fr_syserror(errno));
718+
719+
restore_gid:
720+
if (conf_check_gid != egid) (void) setegid(egid);
718721
return CF_FILE_OTHER_ERROR;
719722
}
720723
}
@@ -723,7 +726,7 @@ cf_file_check_err_t cf_file_check_effective(char const *filename,
723726
if (seteuid(euid) < 0) {
724727
fr_strerror_printf("Failed restoring effective user ID (%d) after file check: %s",
725728
(int) euid, fr_syserror(errno));
726-
return CF_FILE_OTHER_ERROR;
729+
goto restore_gid;
727730
}
728731
}
729732
if (conf_check_gid != egid) {
@@ -3976,13 +3979,18 @@ CONF_ITEM *cf_reference_item(CONF_SECTION const *parent_cs,
39763979
return NULL;
39773980
}
39783981

3979-
if (n2) break;
3980-
39813982
/*
39823983
* "name1[name2", but not "name1[name2]"
3984+
*
3985+
* The inner loop exited because it found *q == '\0',
3986+
* meaning that the closing ']' was never found.
39833987
*/
3984-
fr_strerror_printf("Invalid reference after '%s', missing close ']'", n2);
3985-
return NULL;
3988+
if (!*q) {
3989+
fr_strerror_printf("Invalid reference after '%s', missing close ']'", n1);
3990+
return NULL;
3991+
}
3992+
3993+
break;
39863994
}
39873995
p = q; /* get it ready for the next round */
39883996

0 commit comments

Comments
 (0)