Skip to content
Snippets Groups Projects
Commit ef1d4565 authored by Steven Murray's avatar Steven Murray
Browse files

bug #96536: rmlabelinfo() of tape/initlabel.c corrupts memory if called more than once

Added the unit-test class Ctape_reserveTest correctly this time (ismple forgot
to add it last time).

Ctape_reserve function now passes the unit-tests by return -1 and setting serrno
to EINVAL when more than one drive is requested within a drive reservation
request.
parent a257ebcd
Branches
Tags
No related merge requests found
......@@ -5,15 +5,16 @@
/* Ctape_reserve - reserve tape resources */
#include <errno.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stddef.h>
#include "Ctape.h"
#include "Ctape_api.h"
#include "marshall.h"
#include "serrno.h"
#include <unistd.h>
#include <sys/types.h>
#include "h/Ctape.h"
#include "h/Ctape_api.h"
#include "h/marshall.h"
#include "h/serrno.h"
int Ctape_reserve(int count,
struct dgn_rsv dgn_rsv[])
......@@ -31,6 +32,20 @@ int Ctape_reserve(int count,
int totrsvd = 0;
uid_t uid;
/* Reserving drives from more than one DGN is not supported */
if (1 != count) {
serrno = EINVAL;
return -1;
}
/* Reserving more than one drive from a DGN is not supported */
for (i = 0; i< count; i++) {
if (1 != dgn_rsv[i].num) {
serrno = EINVAL;
return -1;
}
}
strncpy (func, "Ctape_reserve", 16);
uid = getuid();
gid = getgid();
......
/******************************************************************************
* test/unittest/tape/Ctape_reserveTest.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven.Murray@cern.ch
*****************************************************************************/
#ifndef TEST_UNITTEST_TAPE_CTAPERESERVETESTTEST_HPP
#define TEST_UNITTEST_TAPE_CTAPERESERVETESTTEST_HPP 1
#include "h/Ctape_api.h"
#include "h/serrno.h"
#include "test/unittest/test_exception.hpp"
#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include <string.h>
class Ctape_reserveTest: public CppUnit::TestFixture {
public:
void setUp() {
// Do nothing
}
void tearDown() {
// Do nothing
}
/**
* Support for a multiple drive resource lock is being removed as it buggy
* and never used. The new implementation of Ctape_reserve should
* therefore not accept a count parameter value other than 1 and in all other
* cases return -1 and set serrno to EINVAL.
*/
void testCtape_reserveWithCountOf2() {
const int count = 2;
struct dgn_rsv dgn_reservations[2];
memset(dgn_reservations, '\0', sizeof(dgn_reservations));
strncpy(dgn_reservations[0].name, "DGN1",
sizeof(dgn_reservations[0].name - 1));
dgn_reservations[0].num = 1;
strncpy(dgn_reservations[1].name, "DGN2",
sizeof(dgn_reservations[1].name - 1));
dgn_reservations[1].num = 1;
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Calling Ctape_reserve()",
-1,
Ctape_reserve(count, dgn_reservations));
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Checking serrno is set occordingly",
EINVAL,
serrno);
}
/**
* Support for a multiple drive resource lock is being removed as it buggy
* and never used. The new implementation of Ctape_reserve should
* therefore not accept a DGN reservation structure with a drive count other
* than 1 and in all other cases return -1 and set serrno to EINVAL.
*/
void testCtape_reserveWith1DgnReservationWithDriveCountOf2() {
const int count = 1;
struct dgn_rsv dgn_reservation;
memset(&dgn_reservation, '\0', sizeof(dgn_reservation));
strncpy(dgn_reservation.name, "DGN1", sizeof(dgn_reservation.name) - 1);
dgn_reservation.num = 2;
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Calling Ctape_reserve()",
-1,
Ctape_reserve(count, &dgn_reservation));
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Checking serrno is set occordingly",
EINVAL,
serrno);
}
CPPUNIT_TEST_SUITE(Ctape_reserveTest);
CPPUNIT_TEST(testCtape_reserveWithCountOf2);
CPPUNIT_TEST(testCtape_reserveWith1DgnReservationWithDriveCountOf2);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(Ctape_reserveTest);
#endif // TEST_UNITTEST_TAPE_CTAPERESERVETESTTEST
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment