Skip to content

Commit

Permalink
PRD: prevent BitString copy/assignment from BitStringBuffer
Browse files Browse the repository at this point in the history
This prevents bugs where a BitStringBuffer is allocated as a local
variable and passed back to a BitString. In that case, the memory
storage is lost and the BitString will end up poining to bad memory.

Change-Id: Ia53d6bdaddda60723b727575e2b1b8f3bdf48f01
RTC: 167819
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/35695
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Caleb N. Palmer <cnpalmer@us.ibm.com>
Reviewed-by: Benjamin J. Weisenbeck <bweisenb@us.ibm.com>
Reviewed-by: Zane C. Shelley <zshelle@us.ibm.com>
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/36447
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
  • Loading branch information
zane131 committed Feb 15, 2017
1 parent 874cef1 commit 80e0e70
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class ConstantRegister : public SCAN_COMM_REGISTER_CLASS
SCAN_COMM_REGISTER_CLASS( ), iv_iBS(0)
{}

ConstantRegister(BIT_STRING_CLASS i_arg) :
ConstantRegister( const BitStringBuffer & i_arg ) :
SCAN_COMM_REGISTER_CLASS( ), iv_iBS(i_arg)
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2016 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -166,8 +166,8 @@ SCAN_COMM_REGISTER_CLASS & ScanFacility::GetAttnTypeRegister(

//------------------------------------------------------------------------------

SCAN_COMM_REGISTER_CLASS & ScanFacility::GetConstantRegister(
BIT_STRING_CLASS i_val )
SCAN_COMM_REGISTER_CLASS & ScanFacility::GetConstantRegister(
const BitStringBuffer & i_val )
{
ConstantRegister r(i_val);
return iv_constRegFw.get(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2012,2016 */
/* Contributors Listed Below - COPYRIGHT 2012,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -153,7 +153,7 @@ public:
* @post only one instance of the register with this BIT_STRING value will
* exist.
*/
SCAN_COMM_REGISTER_CLASS & GetConstantRegister(BIT_STRING_CLASS i_val);
SCAN_COMM_REGISTER_CLASS & GetConstantRegister(const BitStringBuffer & i_val);
/**
* @brief Get a plugin register
* @param Reference to target less flyweight object
Expand Down
25 changes: 8 additions & 17 deletions src/usr/diag/prdf/common/util/prdfBitString.H
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,16 @@ class BitString
/** @param i_newBitLen The new bit length of this bit string buffer. */
void setBitLen( uint32_t i_newBitLen ) { iv_bitLen = i_newBitLen; }

/*!
Assignment operator
\param string Reference bit string
*/
virtual BitString & operator=(const BitString & string);

private: // functions

// Prevent the assignment operator and copy constructor from a
// BitStringBuffer. While technically these could be done. We run into
// serious problems like with the operator functions above that all return
// a BitStringBuffer. If we allowed these, the BitString would end up
// pointing to memory that is no longer in context.
BitString & operator=( const BitStringBuffer & i_bsb );
BitString( const BitStringBuffer & i_bsb );

/**
* @brief Given a bit position within the bit string, this function returns
* the address that contains the bit position and the bit position
Expand Down Expand Up @@ -456,17 +458,6 @@ std::ostream & operator<<( std::ostream & out,

#endif

inline
BitString & BitString::operator=
(
const BitString & string
)
{
iv_bitLen = string.iv_bitLen;
iv_bufAddr = string.iv_bufAddr;
return(*this);
}

} // end namespace PRDF

#endif

0 comments on commit 80e0e70

Please sign in to comment.