From 990075074f1a47e0b9a03828f82efcf6999bf898 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 12 Jul 2014 10:57:23 +0200 Subject: [PATCH] Fix bug #2074 crashes when no conf file present --- bacula/src/lib/lex.c | 9 +++++++-- bacula/src/lib/parse_conf.c | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index 1fdde032b1..ead211cd2d 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -40,6 +40,9 @@ void scan_to_eol(LEX *lc) lex_unget_char(lc); return; } + if (token == T_EOF) { + return; + } } } @@ -120,7 +123,7 @@ LEX *lex_close_file(LEX *lf) if (lf->bpipe) { close_bpipe(lf->bpipe); lf->bpipe = NULL; - } else { + } else if (lf->fd) { fclose(lf->fd); } Dmsg1(dbglvl, "Close cfg file %s\n", lf->fname); @@ -137,7 +140,9 @@ LEX *lex_close_file(LEX *lf) of = lf; lf = NULL; } - free(of); + if (of) { + free(of); + } return lf; } diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 493a34fa84..b75786fb5b 100644 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -894,16 +894,18 @@ bool CONFIG::parse_config() /* We must create a lex packet to print the error */ lc = (LEX *)malloc(sizeof(LEX)); memset(lc, 0, sizeof(LEX)); + lc->str = get_memory(5000); if (scan_error) { lc->scan_error = scan_error; } else { lex_set_default_error_handler(lc); } lex_set_error_handler_error_type(lc, err_type) ; - bstrncpy(lc->str, cf, sizeof_pool_memory(lc->str)); + pm_strcpy(lc->str, cf); lc->fname = lc->str; scan_err2(lc, _("Cannot open config file \"%s\": %s\n"), lc->str, be.bstrerror()); + free_pool_memory(lc->str); free(lc); return 0; } -- 2.39.5