]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix bug #2074 crashes when no conf file present
authorKern Sibbald <kern@sibbald.com>
Sat, 12 Jul 2014 08:57:23 +0000 (10:57 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 12 Jul 2014 08:57:23 +0000 (10:57 +0200)
bacula/src/lib/lex.c
bacula/src/lib/parse_conf.c

index 1fdde032b12b4de283f8753aac6b514725194ff3..ead211cd2d51754e0ca5b81e0aeb3463d33cf0a1 100644 (file)
@@ -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;
 }
 
index 493a34fa84a6fc8796207f1addd32b045fc787ff..b75786fb5be754ddbad76bc5bd35e3ad9208472f 100644 (file)
@@ -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;
       }