diff options
| author | Marko Kreen | 2013-04-02 20:04:55 +0000 |
|---|---|---|
| committer | Marko Kreen | 2013-04-02 20:04:55 +0000 |
| commit | c0111d42712202df5ccb01c4e07e88ab5c8b94b8 (patch) | |
| tree | 87d025497e5ff0b3d38c058b7e03586de22908b7 | |
| parent | 26ef017ec97c194d4ba5261d617e3e380cc967c6 (diff) | |
cfparser: require that first section must be present
otherwise, when run on empty file, the main section defaults
are not filled in and program may crash.
| -rw-r--r-- | usual/cfparser.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/usual/cfparser.c b/usual/cfparser.c index ff9f4e5..b216d9a 100644 --- a/usual/cfparser.c +++ b/usual/cfparser.c @@ -278,6 +278,7 @@ struct LoaderCtx { const struct CfContext *cf; const char *cur_sect; void *top_base; + bool got_main_sect; }; static bool fill_defaults(struct LoaderCtx *ctx) @@ -289,6 +290,9 @@ static bool fill_defaults(struct LoaderCtx *ctx) if (!s) goto fail; + if (s == ctx->cf->sect_list) + ctx->got_main_sect = true; + if (s->section_start) { if (!s->section_start(ctx->top_base, ctx->cur_sect)) return false; @@ -340,6 +344,10 @@ bool cf_load_file(const struct CfContext *cf, const char *fn) ok = parse_ini_file(fn, load_handler, &ctx); if (ctx.cur_sect) free(ctx.cur_sect); + if (ok && !ctx.got_main_sect) { + log_error("load_init_file: main section missing from config file"); + return false; + } return ok; } |
