@@ -143,7 +143,7 @@ Return Value:
143143
144144 // We assume the controls have been validated first.
145145 PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL pIspCtrl =
146- reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL > ( this + 1 );
146+ reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL >( reinterpret_cast < PBYTE >( this ) + sizeof (CRoiProperty) );
147147
148148 // Loop thru the controls.
149149 for ( ULONG i=0 ; i<m_Hdr.ControlCount ; i++ )
@@ -155,6 +155,11 @@ Return Value:
155155
156156 // Advance to the next control.
157157 pIspCtrl = NextCtrl ( pIspCtrl );
158+ if (pIspCtrl == nullptr )
159+ {
160+ NT_ASSERTMSG (" NextCtrl( pCtrl ) returned 0! Should never happen!" , FALSE );
161+ return nullptr ;
162+ }
158163 }
159164
160165 return nullptr ;
@@ -192,13 +197,18 @@ Return Value:
192197 {
193198 // We assume the controls have been validated first.
194199 PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL pIspCtrl =
195- reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL > ( this + 1 );
200+ reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL >( reinterpret_cast < PBYTE >( this ) + sizeof (CRoiProperty) );
196201
197202 // Loop thru all the controls.
198203 for ( ULONG i=0 ; i<m_Hdr.ControlCount ; i++ )
199204 {
200205 // Advance to the next control.
201206 pIspCtrl = NextCtrl ( pIspCtrl );
207+ if (pIspCtrl == nullptr )
208+ {
209+ NT_ASSERTMSG (" NextCtrl( pCtrl ) returned 0! Should never happen!" , FALSE );
210+ return nullptr ;
211+ }
202212 }
203213
204214 ULONG SizeToCopy = ::GetSize (pCtrl);
@@ -277,14 +287,14 @@ Return Value:
277287 }
278288
279289 PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL pIspCtrl =
280- reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL > ( this + 1 );
290+ reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_ISPCONTROL >( reinterpret_cast < BYTE *>( this ) + sizeof (* this ) );
281291
282292 // Loop thru the controls.
283293 for ( ULONG i=0 ; i<m_Hdr.ControlCount ; i++ )
284294 {
285295 // Make sure there is room to inspect this control
286- if ( Size < ByteDiffPtrs ( this , pIspCtrl+ 1 ) ||
287- m_Hdr.Size < ByteDiffPtrs ( &m_Hdr, pIspCtrl+ 1 ) )
296+ if ( Size < ByteDiffPtrs ( this , reinterpret_cast < PBYTE >( pIspCtrl) + sizeof (*pIspCtrl) ) ||
297+ m_Hdr.Size < ByteDiffPtrs ( &m_Hdr, reinterpret_cast < PBYTE >( pIspCtrl) + sizeof (*pIspCtrl) ) )
288298 {
289299 // NT_ASSERT(FALSE);
290300 DBG_TRACE ( " Failed(1): Size=%d, should be at least %Iu" , Size, ByteDiffPtrs ( this , pIspCtrl+1 ) );
@@ -324,7 +334,7 @@ Return Value:
324334 // Index into to the control's ROI list. Get the equivilent of "pIspCtrl->RoiInfo[j]"
325335 PKSCAMERA_EXTENDEDPROP_ROI_INFO pRoiInfo =
326336 reinterpret_cast <PKSCAMERA_EXTENDEDPROP_ROI_INFO >
327- ((( PBYTE ) ( pIspCtrl+ 1 )) + (j * GetSizeOfRoiInfo (pIspCtrl->ControlId ) ));
337+ ((reinterpret_cast < PBYTE >(pIspCtrl) + sizeof (* pIspCtrl)) + (j * GetSizeOfRoiInfo (pIspCtrl->ControlId ) ));
328338
329339 // Validate the cooridinates
330340 if ( pRoiInfo->Region .top < (LONG ) TO_Q31 (0 ) ||
@@ -500,6 +510,11 @@ Log()
500510
501511 // Advance to the next control.
502512 pIspCtrl = reinterpret_cast <CRoiIspControl *>( NextCtrl ( pIspCtrl ) ) ;
513+ if (pIspCtrl == nullptr )
514+ {
515+ NT_ASSERTMSG (" NextCtrl( pCtrl ) returned 0! Should never happen!" , FALSE );
516+ return ;
517+ }
503518 }
504519}
505520
0 commit comments