Skip to content

Commit

Permalink
sd: Avoid segfault in is_vol_in_autochanger().
Browse files Browse the repository at this point in the history
If the sd config file contains a Device section for a device not
listed in the Autochanger config section, is_vol_in_autochanger()
might be called with vol->dev->device->changer_res being NULL.
However, the function dereferences this pointer unconditionally,
which results in a segfault.

This patch adds the necessary check and returns false in this case,
avoiding the crash.

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
Andre Noll authored and Marco van Wieringen committed Jul 15, 2013
1 parent 301891c commit 669f153
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/stored/reserve.c
Expand Up @@ -378,8 +378,7 @@ static bool use_device_cmd(JCR *jcr)


/*
* Walk through the autochanger resources and check if
* the volume is in one of them.
* Walk through the autochanger resources and check if the volume is in one of them.
*
* Returns: true if volume is in device
* false otherwise
Expand All @@ -388,7 +387,13 @@ static bool is_vol_in_autochanger(RCTX &rctx, VOLRES *vol)
{
AUTOCHANGERRES *changer = vol->dev->device->changer_res;

/* Find resource, and make sure we were able to open it */
if (!changer) {
return false;
}

/*
* Find resource, and make sure we were able to open it
*/
if (bstrcmp(rctx.device_name, changer->hdr.name)) {
Dmsg1(dbglvl, "Found changer device %s\n", vol->dev->device->hdr.name);
return true;
Expand Down

0 comments on commit 669f153

Please sign in to comment.