Skip to content

Commit 677e8ec

Browse files
committed
tweak dict_from_file to be a bit more forgiving
1 parent d91ca0d commit 677e8ec

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/lib/util/dict_tokenize.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct dict_tokenize_ctx_s {
102102
};
103103

104104
static int _dict_from_file(dict_tokenize_ctx_t *dctx,
105-
char const *dir_name, char const *filename,
105+
char const *dir_name, char const *filename,
106106
char const *src_file, int src_line);
107107

108108
#define CURRENT_FRAME(_dctx) (&(_dctx)->stack[(_dctx)->stack_depth])
@@ -3225,11 +3225,6 @@ static int _dict_from_file(dict_tokenize_ctx_t *dctx,
32253225

32263226
if (!fr_cond_assert(!dctx->dict->root || CURRENT_FRAME(dctx)->da)) return -1;
32273227

3228-
if ((strlen(dir) + 2 + strlen(filename)) > sizeof(filename_buf)) {
3229-
fr_strerror_printf("%s: Filename name too long", "Error reading dictionary");
3230-
return -1;
3231-
}
3232-
32333228
/*
32343229
* The filename is relative to the current directory.
32353230
*
@@ -3240,6 +3235,16 @@ static int _dict_from_file(dict_tokenize_ctx_t *dctx,
32403235
char const *q;
32413236
bool slash = false;
32423237

3238+
if (!dir) {
3239+
fr_strerror_printf("Error reading dictionary: No directory was supplied");
3240+
return -1;
3241+
}
3242+
3243+
if ((strlen(dir) + 2 + strlen(filename)) > sizeof(filename_buf)) {
3244+
fr_strerror_printf("%s: Filename name too long", "Error reading dictionary");
3245+
return -1;
3246+
}
3247+
32433248
/*
32443249
* We either have to do strcpy + strrchr(), or manual checks.
32453250
*/

0 commit comments

Comments
 (0)