Ejemplo n.º 1
0
void *DCERPC_FragAlloc(void *p, u_int16_t old_size, u_int16_t *new_size)
{
    u_int16_t add_size = *new_size - old_size;

    if ( (((u_int32_t) add_size) + _total_memory) > _memcap )
    {
        /* Raise alert */
        if ( _alert_memcap )
        {
            DCERPC_GenerateAlert(DCERPC_EVENT_MEMORY_OVERFLOW, 
                                    DCERPC_EVENT_MEMORY_OVERFLOW_STR);
        }
        add_size = (u_int16_t) (_memcap - _total_memory);
    }

    _total_memory += add_size;
    *new_size = old_size + add_size;

    if ( !p )
    {
        return malloc(*new_size);
    }

    return realloc(p, *new_size);
}
Ejemplo n.º 2
0
void *DCERPC_FragAlloc(void *p, u_int16_t old_size, u_int16_t *new_size)
{
    u_int16_t add_size;
    void *new_buf = NULL;

    if (old_size >= *new_size)
    {
        *new_size = old_size;
        return p;
    }

    add_size = *new_size - old_size;

    if ( (((u_int32_t) add_size) + _total_memory) > _memcap )
    {
        /* Raise alert */
        if ( _alert_memcap )
        {
            DCERPC_GenerateAlert(DCERPC_EVENT_MEMORY_OVERFLOW, 
                                    DCERPC_EVENT_MEMORY_OVERFLOW_STR);
        }
        add_size = (u_int16_t) (_memcap - _total_memory);
    }

    *new_size = old_size + add_size;

    if (*new_size == old_size)
        return p;

    new_buf = calloc(*new_size, 1);

    if (new_buf == NULL)
    {
        if (p != NULL)
        {
            DCERPC_FragFree(p, old_size);
        }

        return NULL;
    }

    if (p != NULL)
    {
        int ret;

        ret = SafeMemcpy(new_buf, p, old_size, new_buf, (u_int8_t *)new_buf + *new_size);

        if (ret == 0)
        {
            *new_size = old_size;
            free(new_buf);
            return p;
        }

        DCERPC_FragFree(p, old_size);
    }

    /* DCERPC_FragFree will decrement old_size from _total_memory so
     * we add the *new_size */
    _total_memory += *new_size;

    return new_buf;
}