예제 #1
0
파일: amsg_verify.c 프로젝트: genua/anoubis
static int
anoubisd_msg_eventask_size(const char *buf, int buflen)
{
	struct anoubisd_msg_eventask	*msg;
	struct buf_offset		 offs[5];
	int				 i, j, total = 0;
	DECLARE_SIZE();

	CAST(msg, buf, buflen);

	/* Detect offset overlaps */
	ADDOFFSET(0, csum);
	ADDOFFSET(1, path);
	ADDOFFSET(2, ctxcsum);
	ADDOFFSET(3, ctxpath);
	ADDOFFSET(4, ev);

	for (i=0; i<5; ++i) {
		int	s1, e1;
		if (offs[i].len == 0)
			continue;
		s1 = offs[i].off;
		e1 = s1 + offs[i].len;
		if (e1 > total)
			total = e1;
		for (j=0; j<i; ++j) {
			int	s2, e2;
			if (offs[j].len == 0)
				continue;
			s2 = offs[j].off;
			e2 = s2 + offs[j].len;
			if (s2 < e1 && s1 < e2)
				return -1;
		}
	}

	SHIFT_FIELD(msg, payload, buf, buflen);
	if (total > buflen)
		return -1;
	ADD_SIZE(total);
	if (msg->pathlen)
		CHECK_STRING(buf+msg->pathoff, msg->pathlen);
	if (msg->ctxpathlen)
		CHECK_STRING(buf+msg->ctxpathoff, msg->ctxpathlen);
	if (msg->evlen) {
		int	size = eventdev_hdr_size(buf+msg->evoff, msg->evlen);
		CHECK_SIZE(size);
	}
	RETURN_SIZE();
}
예제 #2
0
// Wrapper for realloc.  Adds debug info then mimics realloc behavior
void* __wrap_realloc(void* pAllocMem, size_t size)
{
#ifdef MEMPOOL_ENABLED
    void* tempPtr;
#endif

#ifndef MEMDEBUG_ENABLED
 
    return REALLOC(pAllocMem,size);

#else
    void* pNewAllocMem;
    volatile int pReturnFnAddress;
    GET_RTNFNADDR;

    if (tMemDebug::m_Enabled && ((pAllocMem==0) || tMemDebug::HasDebugInfo(pAllocMem)))
    {

        if (pAllocMem) 
        {
            tMemDebug::Free(pAllocMem);
            pNewAllocMem = REALLOC((void*)SUBOFFSET(pAllocMem),
                                          size+ALLOC_OFFSET);
        }
        else
            pNewAllocMem = MALLOC(size+ALLOC_OFFSET);
          
        if (pNewAllocMem)
        {
            tMemDebug::Allocate(pNewAllocMem,pReturnFnAddress,size);
            tMemDebug::CheckForTrace((char*)"rallc",(void*)ADDOFFSET(pNewAllocMem),
                                     pReturnFnAddress,true);
            return ((void*)ADDOFFSET(pNewAllocMem));
        }
        else
            return 0;
    }
    else
    {
        pNewAllocMem = REALLOC(pAllocMem, size);
        if (pAllocMem) tMemDebug::IncrementAllocStats();
        return pNewAllocMem;
    }
#endif // MEMDEBUG_ENABLED
}
예제 #3
0
// Wrapper for calloc.  Add debug info, zero the data, then call the real malloc.
void* __wrap_calloc(size_t nmemb, size_t size)
{
#ifndef MEMDEBUG_ENABLED

    return CALLOC(nmemb,size);

#else // MEMDEBUG_ENABLED

#ifdef MEMPOOL_ENABLED
    void* tempPtr;
#endif
    void* pAllocMem;
    volatile int pReturnFnAddress;
    GET_RTNFNADDR;

    if (tMemDebug::m_Enabled)
    {
        pAllocMem = MALLOC(nmemb*size+ALLOC_OFFSET);

        if (pAllocMem)
        {
            unsigned int i;
            char* ptr=(char*)ADDOFFSET(pAllocMem);
            // zero out the buffer
            for (i=0; i<(nmemb*size); i++) 
                *ptr++=0;

            tMemDebug::Allocate(pAllocMem,pReturnFnAddress,nmemb*size);
            tMemDebug::CheckForTrace((char*)"callc",(void*)ADDOFFSET(pAllocMem),
                                     pReturnFnAddress,true);
            return ((void*)ADDOFFSET(pAllocMem));
        }
        else
            return 0;
    }
    else
    {
        pAllocMem = CALLOC(nmemb,size);
        tMemDebug::IncrementAllocStats();
        return pAllocMem;
    }
#endif // MEMDEBUG_ENABLED
}
예제 #4
0
// override new operator
void* operator new(unsigned int size) 
{
#ifdef MEMPOOL_ENABLED
    void* tempPtr;
#endif

#ifndef MEMDEBUG_ENABLED

    return MALLOC(size);

#else

    void* pAllocMem;
    volatile int pReturnFnAddress=0;
    GET_RTNFNADDR;

    if (tMemDebug::m_Enabled)
    {
        pAllocMem = MALLOC(size+ALLOC_OFFSET);

        if (pAllocMem)
        {
            tMemDebug::Allocate(pAllocMem,pReturnFnAddress, size);
            tMemDebug::CheckForTrace((char*)"new  ",(void*)ADDOFFSET(pAllocMem),
                                     pReturnFnAddress,true);
            return ((void*)ADDOFFSET(pAllocMem));
        }
        else
            throw std::bad_alloc();
    }
    else
    {   
        pAllocMem = MALLOC(size);
        tMemDebug::IncrementAllocStats();
        return pAllocMem;
    }
#endif // MEMDEBUG_ENABLED
}
예제 #5
0
// Wrapper for malloc.  Adds debug info and then calls the real malloc
void* __wrap_malloc(size_t size)
{
#ifdef MEMPOOL_ENABLED
    void* tempPtr;
#endif

#ifndef MEMDEBUG_ENABLED

    return MALLOC(size);

#else // MEMDEBUG_ENABLED

    void* pAllocMem;
    volatile int pReturnFnAddress;
    GET_RTNFNADDR;

    if (tMemDebug::m_Enabled)
    {
        pAllocMem = MALLOC(size+ALLOC_OFFSET);

        if (pAllocMem)
        {
            tMemDebug::Allocate(pAllocMem,pReturnFnAddress,size);
            tMemDebug::CheckForTrace((char*)"mallc",(void*)ADDOFFSET(pAllocMem),
                                     pReturnFnAddress,true);
            return ((void*)ADDOFFSET(pAllocMem));
        }
        else
            return 0;
    }
    else
    {
        pAllocMem = MALLOC(size);
        tMemDebug::IncrementAllocStats();
        return pAllocMem;
    }
#endif // MEMDEBUG_ENABLED
}