https://github.com/N-BodyShop/changa
Revision 210f115c289db4a1c9123483863fd225fc3a5819 authored by Tim Haines on 10 December 2017, 10:35:00 UTC, committed by Tim Haines on 22 October 2018, 21:06:50 UTC
Compiling with gcc-7.2 shows calculated string sizes possibly larger than buffer size. This also fixes undefined behavior in dumpframe.dfReadColorMapFile.

Change-Id: Ib57f3d868ce0e37251658e9778c88fc4dc66ac82
1 parent f9a522d
Raw File
Tip revision: 210f115c289db4a1c9123483863fd225fc3a5819 authored by Tim Haines on 10 December 2017, 10:35:00 UTC
Fix possible buffer overflows in calls to sprintf
Tip revision: 210f115
DumpFrameData.h
#ifndef DUMP_FRAME_DATA_H
#define DUMP_FRAME_DATA_H

#include "ParallelGravity.h"
#include "Reductions.h"

/// @brief Group to hold the frame buffer memory.
class DumpFrameData : public CBase_DumpFrameData 
{
    void *bufImage;
    int nImage;
  public:
    void *Image;

    DumpFrameData() { bufImage = NULL; }
    DumpFrameData(CkMigrateMessage *m) : CBase_DumpFrameData(m) { bufImage = NULL;}
    void pup(PUP::er &p) { CBase_DumpFrameData::pup(p); }
    ~DumpFrameData() { if(bufImage) free(bufImage); }
    /// @brief
    void clearFrame(InDumpFrame in, const CkCallback& cb) {
	if(bufImage == NULL)
	    bufImage = malloc(sizeof(in) + in.nxPix*in.nyPix*sizeof(DFIMAGE));
	Image = ((char *)bufImage) + sizeof(in);
	*((struct inDumpFrame *)bufImage) = in; //start of reduction
						//message is the parameters
	dfClearImage( &in, Image, &nImage);
	contribute(cb);
	}
    
    void combineFrame(InDumpFrame in, const CkCallback& cb) {
	contribute(sizeof(in) + nImage, bufImage, dfImageReduction, cb);
	free(bufImage);
	bufImage = NULL;
	}
    };

#endif
back to top