From c55554a3e1d471b4f1c5ff0123532f8e5893099d Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 20 Jan 2010 20:59:44 +0100 Subject: [PATCH] Fix FD crash when plugin running and cancel given --- bacula/src/filed/fd_plugins.c | 19 +++++++++++++++++++ bacula/src/findlib/bfile.c | 12 +++++------- bacula/src/plugins/fd/bpipe-fd.c | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index a37d13d7c2..df13465431 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -711,6 +711,9 @@ static int my_plugin_bopen(BFILE *bfd, const char *fname, int flags, mode_t mode struct io_pkt io; Dmsg1(dbglvl, "plugin_bopen flags=%x\n", flags); + if (!plugin || !jcr->plugin_ctx) { + return 0; + } io.pkt_size = sizeof(io); io.pkt_end = sizeof(io); io.func = IO_OPEN; @@ -738,7 +741,11 @@ static int my_plugin_bclose(BFILE *bfd) JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; struct io_pkt io; + Dmsg0(dbglvl, "===== plugin_bclose\n"); + if (!plugin || !jcr->plugin_ctx) { + return 0; + } io.pkt_size = sizeof(io); io.pkt_end = sizeof(io); io.func = IO_CLOSE; @@ -763,7 +770,11 @@ static ssize_t my_plugin_bread(BFILE *bfd, void *buf, size_t count) JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; struct io_pkt io; + Dmsg0(dbglvl, "plugin_bread\n"); + if (!plugin || !jcr->plugin_ctx) { + return 0; + } io.pkt_size = sizeof(io); io.pkt_end = sizeof(io); io.func = IO_READ; @@ -787,7 +798,11 @@ static ssize_t my_plugin_bwrite(BFILE *bfd, void *buf, size_t count) JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; struct io_pkt io; + Dmsg0(dbglvl, "plugin_bwrite\n"); + if (!plugin || !jcr->plugin_ctx) { + return 0; + } io.pkt_size = sizeof(io); io.pkt_end = sizeof(io); io.func = IO_WRITE; @@ -811,7 +826,11 @@ static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence) JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; struct io_pkt io; + Dmsg0(dbglvl, "plugin_bseek\n"); + if (!plugin || !jcr->plugin_ctx) { + return 0; + } io.pkt_size = sizeof(io); io.pkt_end = sizeof(io); io.func = IO_SEEK; diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 3a98480029..1bc4423a9f 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2008 Free Software Foundation Europe e.V. + Copyright (C) 2003-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -32,8 +32,6 @@ * * Kern Sibbald, April MMIII * - * Version $Id$ - * */ #include "bacula.h" @@ -617,10 +615,6 @@ int bclose(BFILE *bfd) { int stat = 0; - if (bfd->errmsg) { - free_pool_memory(bfd->errmsg); - bfd->errmsg = NULL; - } if (bfd->mode == BF_CLOSED) { Dmsg0(50, "=== BFD already closed.\n"); return 0; @@ -668,6 +662,10 @@ int bclose(BFILE *bfd) } all_done: + if (bfd->errmsg) { + free_pool_memory(bfd->errmsg); + bfd->errmsg = NULL; + } bfd->mode = BF_CLOSED; bfd->lpContext = NULL; bfd->cmd_plugin = false; diff --git a/bacula/src/plugins/fd/bpipe-fd.c b/bacula/src/plugins/fd/bpipe-fd.c index 52521cd154..03c3940a5d 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2009 Free Software Foundation Europe e.V. + Copyright (C) 2007-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -173,6 +173,9 @@ static bRC newPlugin(bpContext *ctx) static bRC freePlugin(bpContext *ctx) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } if (p_ctx->cmd) { free(p_ctx->cmd); /* free any allocated command string */ } @@ -203,6 +206,10 @@ static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } + // char *name; /* @@ -284,6 +291,9 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } time_t now = time(NULL); sp->fname = p_ctx->fname; sp->type = FT_REG; @@ -318,6 +328,9 @@ static bRC endBackupFile(bpContext *ctx) static bRC pluginIO(bpContext *ctx, struct io_pkt *io) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } io->status = 0; io->io_errno = 0; -- 2.39.5