From 365d594a124082324c4ed360f7b581b42c682e88 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 23 Jun 2003 19:21:42 +0000 Subject: [PATCH] Fix possible buffer overrun in restore tree routine git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@608 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/ua_tree.c | 4 ++-- bacula/src/stored/askdir.c | 10 +++++----- bacula/src/stored/autochanger.c | 2 +- bacula/src/stored/dev.h | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index a3ae58683c..8b855085f8 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -126,7 +126,7 @@ void user_select_files_from_tree(TREE_CTX *tree) int insert_tree_handler(void *ctx, int num_fields, char **row) { TREE_CTX *tree = (TREE_CTX *)ctx; - char fname[2000]; + char fname[5000]; TREE_NODE *node, *new_node; int type; @@ -140,7 +140,7 @@ int insert_tree_handler(void *ctx, int num_fields, char **row) } else { type = TN_FILE; } - sprintf(fname, "%s%s", row[0], row[1]); + bsnprintf(fname, sizeof(fname), "%s%s", row[0]?row[0]:"", row[1]?row[1]:""); if (tree->avail_node) { node = tree->avail_node; } else { diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index bad70ce0af..ac8f928441 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -321,7 +321,7 @@ Please use the \"label\" command to create a new Volume for:\n\ Mmsg(&dev->errmsg, _("Gave up waiting to mount Storage Device \"%s\" for Job %s\n"), jcr->dev_name, jcr->Job); Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg); - Dmsg1(190, "Gave up waiting on device %s\n", dev->dev_name); + Dmsg1(190, "Gave up waiting on device %s\n", dev_name(dev)); return 0; /* exceeded maximum waits */ } continue; @@ -336,7 +336,7 @@ Please use the \"label\" command to create a new Volume for:\n\ Jmsg(jcr, M_WARNING, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat, strerror(stat)); } - Dmsg1(190, "Someone woke me for device %s\n", dev->dev_name); + Dmsg1(190, "Someone woke me for device %s\n", dev_name(dev)); /* Restart wait counters */ wait_sec = min_wait; @@ -413,7 +413,7 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) Mmsg(&dev->errmsg, _("Gave up waiting to mount Storage Device \"%s\" for Job %s\n"), jcr->dev_name, jcr->Job); Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg); - Dmsg1(190, "Gave up waiting on device %s\n", dev->dev_name); + Dmsg1(190, "Gave up waiting on device %s\n", dev_name(dev)); return 0; /* exceeded maximum waits */ } continue; @@ -428,7 +428,7 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) Jmsg(jcr, M_ERROR, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat, strerror(stat)); } - Dmsg1(190, "Someone woke me for device %s\n", dev->dev_name); + Dmsg1(190, "Someone woke me for device %s\n", dev_name(dev)); /* Restart wait counters */ wait_sec = min_wait; @@ -476,7 +476,7 @@ static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec) for ( ; !job_canceled(jcr); ) { time_t now; - Dmsg3(100, "I'm going to sleep on device %s. HB=%d wait=%d\n", dev->dev_name, + Dmsg3(100, "I'm going to sleep on device %s. HB=%d wait=%d\n", dev_name(dev), (int)me->heartbeat_interval, wait_sec); stat = pthread_cond_timedwait(&dev->wait_next_vol, &dev->mutex, &timeout); Dmsg1(100, "Wokeup from sleep on device stat=%d\n", stat); diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 46922205b2..a6a19870c9 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -222,7 +222,7 @@ static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd) str = "%"; break; case 'a': - str = jcr->device->dev->dev_name; + str = dev_name(jcr->device->dev); break; case 'c': str = NPRT(jcr->device->changer_name); diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 9f8eeb2c38..70e7b9b8f1 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -143,9 +143,10 @@ struct DEVRES; /* Device resource defined in stored_conf. /* Device structure definition */ struct DEVICE { +public: DEVICE *next; /* pointer to next open device */ DEVICE *prev; /* pointer to prev open device */ - JCR *attached_jcrs; /* attached JCR list */ + JCR *attached_jcrs; /* attached JCR list */ pthread_mutex_t mutex; /* access control */ pthread_cond_t wait; /* thread wait variable */ pthread_cond_t wait_next_vol; /* wait for tape to be mounted */ @@ -179,7 +180,7 @@ struct DEVICE { VOLUME_CAT_INFO VolCatInfo; /* Volume Catalog Information */ VOLUME_LABEL VolHdr; /* Actual volume label */ - + }; -- 2.39.5