VirtualBox

Changeset 74890 in vbox for trunk


Ignore:
Timestamp:
Oct 17, 2018 4:58:38 PM (6 years ago)
Author:
vboxsync
Message:

3D: Memory allocations fixed, bugref:9251. Merged changes r125768, r125779, r125780, r125812.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:mergeinfo
      •  

        old new  
        88/branches/VBox-5.0:104445,104938,104943,104950,104952-104953,104987-104988,104990,106453
        99/branches/VBox-5.1:112367,115992,116543,116550,116568,116573
        10 /branches/VBox-5.2:120083,120099,120213,120221,120239,123597-123598,123600-123601,123755
         10/branches/VBox-5.2:120083,120099,120213,120221,120239,123597-123598,123600-123601,123755,125768,125779-125780,125812
        1111/branches/andy/draganddrop:90781-91268
        1212/branches/andy/guestctrl20:78916,78930
  • trunk/src/VBox

    • Property svn:mergeinfo
      •  

        old new  
        88/branches/VBox-5.0/src/VBox:104938,104943,104950,104987-104988,104990,106453
        99/branches/VBox-5.1/src/VBox:112367,116543,116550,116568,116573
        10 /branches/VBox-5.2/src/VBox:120083,120099,120213,120221,120239,123597-123598,123600-123601,123755
         10/branches/VBox-5.2/src/VBox:120083,120099,120213,120221,120239,123597-123598,123600-123601,123755,125768,125779-125780,125812
        1111/branches/andy/draganddrop/src/VBox:90781-91268
        1212/branches/andy/guestctrl20/src/VBox:78916,78930
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_pixel.c

    r70601 r74890  
    343343void STATE_APIENTRY crStatePixelMapusv (GLenum map, GLint mapsize, const GLushort * values)
    344344{
    345     GLfloat fvalues[CR_MAX_PIXEL_MAP_TABLE];
    346     GLint i;
     345    if (mapsize < 0 || mapsize > CR_MAX_PIXEL_MAP_TABLE)
     346    {
     347        crError("crStatePixelMapusv: parameter 'mapsize' is out of range");
     348        return;
     349    }
    347350
    348351    if (!crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
    349352    {
     353        GLfloat fvalues[CR_MAX_PIXEL_MAP_TABLE];
     354        GLint i;
     355
    350356        if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
    351357           for (i=0;i<mapsize;i++) {
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_bufferobject.c

    r69390 r74890  
    2626crServerDispatchGenBuffersARB(GLsizei n, GLuint *buffers)
    2727{
    28         GLuint *local_buffers = (GLuint *) crAlloc( n * sizeof(*local_buffers) );
    29         (void) buffers;
     28    GLuint *local_buffers;
     29    (void) buffers;
    3030
    31         crStateGenBuffersARB(n, local_buffers);
     31    if (n >= INT32_MAX / sizeof(GLuint))
     32    {
     33        crError("crServerDispatchGenBuffersARB: parameter 'n' is out of range");
     34        return;
     35    }
    3236
    33         crServerReturnValue( local_buffers, n * sizeof(*local_buffers) );
    34         crFree( local_buffers );
     37    local_buffers = (GLuint *)crCalloc(n * sizeof(*local_buffers));
     38
     39    if (!local_buffers)
     40    {
     41        crError("crServerDispatchGenBuffersARB: out of memory");
     42        return;
     43    }
     44
     45    crStateGenBuffersARB(n, local_buffers);
     46
     47    crServerReturnValue( local_buffers, n * sizeof(*local_buffers) );
     48    crFree( local_buffers );
    3549}
    3650
     
    5064
    5165void SERVER_DISPATCH_APIENTRY
    52 crServerDispatchGetBufferSubDataARB(GLenum target, GLintptrARB offset,
    53                                                                                                                                                 GLsizeiptrARB size, void * data)
     66crServerDispatchGetBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data)
    5467{
    55         void *b;
     68    void *b;
    5669
    57         b = crAlloc(size);
    58         if (b) {
    59                 cr_server.head_spu->dispatch_table.GetBufferSubDataARB( target, offset, size, b );
     70    b = crCalloc(size);
     71    if (b) {
     72        cr_server.head_spu->dispatch_table.GetBufferSubDataARB( target, offset, size, b );
    6073
    61                 crServerReturnValue( b, size );
    62                 crFree( b );
    63         }
    64         else {
    65                 crError("Out of memory in crServerDispatchGetBufferSubDataARB");
    66         }
     74        crServerReturnValue( b, size );
     75        crFree( b );
     76    }
     77    else {
     78        crError("Out of memory in crServerDispatchGetBufferSubDataARB");
     79    }
    6780}
    6881
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_framebuffer.c

    r69500 r74890  
    2626crServerDispatchGenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
    2727{
    28     GLuint *local_buffers = (GLuint *) crAlloc(n * sizeof(*local_buffers));
     28    GLuint *local_buffers;
    2929    (void) framebuffers;
     30
     31    if (n >= INT32_MAX / sizeof(GLuint))
     32    {
     33        crError("crServerDispatchGenFramebuffersEXT: parameter 'n' is out of range");
     34        return;
     35    }
     36
     37    local_buffers = (GLuint *)crCalloc(n * sizeof(*local_buffers));
    3038
    3139    crStateGenFramebuffersEXT(n, local_buffers);
     
    3846crServerDispatchGenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
    3947{
    40     GLuint *local_buffers = (GLuint *) crAlloc(n * sizeof(*local_buffers));
     48    GLuint *local_buffers;
    4149    (void) renderbuffers;
     50
     51    if (n >= INT32_MAX / sizeof(GLuint))
     52    {
     53        crError("crServerDispatchGenRenderbuffersEXT: parameter 'n' is out of range");
     54        return;
     55    }
     56
     57    local_buffers = (GLuint *)crCalloc(n * sizeof(*local_buffers));
    4258
    4359    crStateGenRenderbuffersEXT(n, local_buffers);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_gentextures.c

    r69390 r74890  
    1414void SERVER_DISPATCH_APIENTRY crServerDispatchGenTextures( GLsizei n, GLuint *textures )
    1515{
    16     GLuint *local_textures = (GLuint *) crAlloc(n*sizeof(*local_textures));
     16    GLuint *local_textures;
    1717    (void) textures;
     18
     19    if (n >= INT32_MAX / sizeof(GLuint))
     20    {
     21        crError("crServerDispatchGenTextures: parameter 'n' is out of range");
     22        return;
     23    }
     24
     25    local_textures = (GLuint *)crCalloc(n * sizeof(*local_textures));
     26
     27    if (!local_textures)
     28    {
     29        crError("crServerDispatchGenTextures: out of memory");
     30        return;
     31    }
    1832
    1933    crStateGenTextures(n, local_textures);
     
    2539void SERVER_DISPATCH_APIENTRY crServerDispatchGenProgramsNV( GLsizei n, GLuint * ids )
    2640{
    27     GLuint *local_progs = (GLuint *) crAlloc( n*sizeof( *local_progs) );
     41    GLuint *local_progs;
    2842    (void) ids;
     43
     44    if (n >= INT32_MAX / sizeof(GLuint))
     45    {
     46        crError("crServerDispatchGenProgramsNV: parameter 'n' is out of range");
     47        return;
     48    }
     49
     50    local_progs = (GLuint *)crCalloc(n * sizeof(*local_progs));
     51
     52    if (!local_progs)
     53    {
     54        crError("crServerDispatchGenProgramsNV: out of memory");
     55        return;
     56    }
     57
    2958    cr_server.head_spu->dispatch_table.GenProgramsNV( n, local_progs );
    3059    crServerReturnValue( local_progs, n*sizeof( *local_progs ) );
     
    3564void SERVER_DISPATCH_APIENTRY crServerDispatchGenFencesNV( GLsizei n, GLuint * ids )
    3665{
    37     GLuint *local_fences = (GLuint *) crAlloc( n*sizeof( *local_fences) );
     66    GLuint *local_fences;
    3867    (void) ids;
     68
     69    if (n >= INT32_MAX / sizeof(GLuint))
     70    {
     71        crError("crServerDispatchGenFencesNV: parameter 'n' is out of range");
     72        return;
     73    }
     74
     75    local_fences = (GLuint *)crCalloc(n * sizeof(*local_fences));
     76
     77    if (!local_fences)
     78    {
     79        crError("crServerDispatchGenFencesNV: out of memory");
     80        return;
     81    }
     82
    3983    cr_server.head_spu->dispatch_table.GenFencesNV( n, local_fences );
    4084    crServerReturnValue( local_fences, n*sizeof( *local_fences ) );
     
    4791    GLsizei i;
    4892    (void) ids;
     93
     94    if (n >= INT32_MAX / sizeof(GLuint))
     95    {
     96        crError("crServerDispatchGenProgramsARB: parameter 'n' is out of range");
     97        return;
     98    }
     99
     100    local_progs = (GLuint *)crCalloc(n * sizeof(*local_progs));
     101
     102    if (!local_progs)
     103    {
     104        crError("crServerDispatchGenProgramsARB: out of memory");
     105        return;
     106    }
     107
    49108    cr_server.head_spu->dispatch_table.GenProgramsARB( n, local_progs );
    50109
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getshaders.c

    r73223 r74890  
    4040
    4141    if (bufSize < INT32_MAX / 2)
    42         pLocal = (crGetActive_t*)crAlloc(bufSize + sizeof(crGetActive_t));
     42        pLocal = (crGetActive_t*)crCalloc(bufSize + sizeof(crGetActive_t));
    4343
    4444    if (!pLocal)
     
    4949        return;
    5050    }
    51     /* zero out just the header to ensure it initially contains zero size values */
    52     memset(pLocal, 0, sizeof (*pLocal));
     51
    5352    cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
    5453    crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
     
    6160
    6261    if (bufSize < INT32_MAX / 2)
    63         pLocal = (crGetActive_t*) crAlloc(bufSize + sizeof(crGetActive_t));
     62        pLocal = (crGetActive_t*) crCalloc(bufSize + sizeof(crGetActive_t));
    6463
    6564    if (!pLocal)
     
    7069        return;
    7170    }
    72     /* zero out just the header to ensure it initially contains zero size values */
    73     memset(pLocal, 0, sizeof (*pLocal));
     71
    7472    cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
    7573    crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
     
    8280
    8381    if (maxCount < INT32_MAX / sizeof(GLuint) / 2)
    84         pLocal = (GLsizei*) crAlloc(maxCount * sizeof(GLuint) + sizeof(GLsizei));
     82        pLocal = (GLsizei*) crCalloc(maxCount * sizeof(GLuint) + sizeof(GLsizei));
    8583
    8684    if (!pLocal)
     
    111109
    112110    if (maxCount < INT32_MAX / sizeof(VBoxGLhandleARB) / 2)
    113         pLocal = (GLsizei*) crAlloc(maxCount * sizeof(VBoxGLhandleARB) + sizeof(GLsizei));
     111        pLocal = (GLsizei*) crCalloc(maxCount * sizeof(VBoxGLhandleARB) + sizeof(GLsizei));
    114112
    115113    if (!pLocal)
     
    143141
    144142    if (maxLength < INT32_MAX / 2)
    145         pLocal = (GLsizei*) crAlloc(maxLength + sizeof(GLsizei));
     143        pLocal = (GLsizei*) crCalloc(maxLength + sizeof(GLsizei));
    146144
    147145    if (!pLocal)
     
    167165
    168166    if (bufSize < INT32_MAX / 2)
    169         pLocal = (GLsizei*) crAlloc(bufSize + sizeof(GLsizei));
     167        pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
    170168
    171169    if (!pLocal)
     
    187185
    188186    if (bufSize < INT32_MAX / 2)
    189         pLocal = (GLsizei*) crAlloc(bufSize + sizeof(GLsizei));
     187        pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
    190188
    191189    if (!pLocal)
     
    208206
    209207    if (bufSize < INT32_MAX / 2)
    210         pLocal = (GLsizei*) crAlloc(bufSize + sizeof(GLsizei));
     208        pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
    211209
    212210    if (!pLocal)
     
    233231
    234232    if (maxcbData < INT32_MAX / 2)
    235         pLocal = (GLsizei*) crAlloc(maxcbData + sizeof(GLsizei));
     233        pLocal = (GLsizei*) crCalloc(maxcbData + sizeof(GLsizei));
    236234
    237235    if (!pLocal)
     
    259257
    260258    if (maxcbData < INT32_MAX / 2)
    261         pLocal = (GLsizei*) crAlloc(maxcbData + sizeof(GLsizei));
     259        pLocal = (GLsizei*) crCalloc(maxcbData + sizeof(GLsizei));
    262260
    263261    if (!pLocal)
     
    292290    GLfloat *pLocal;
    293291
    294     pLocal = (GLfloat*) crAlloc(size);
     292    pLocal = (GLfloat*) crCalloc(size);
    295293    if (!pLocal)
    296294    {
     
    311309    GLint *pLocal;
    312310
    313     pLocal = (GLint*) crAlloc(size);
     311    pLocal = (GLint*) crCalloc(size);
    314312    if (!pLocal)
    315313    {
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getteximage.c

    r69390 r74890  
    7777#endif
    7878
    79     if (size && (buffer = crAlloc(size))) {
     79    if (size && (buffer = crCalloc(size))) {
    8080        /* Note, the other pixel PACK parameters (default values) should
    8181         * be OK at this point.
     
    118118    cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
    119119
    120     if (size && (buffer = crAlloc(size))) {
     120    if (size && (buffer = crCalloc(size))) {
    121121        /* XXX the pixel PACK parameter should be OK at this point */
    122122        cr_server.head_spu->dispatch_table.GetCompressedTexImageARB(target, level, buffer);
     
    149149        GLubyte local_mask[128];
    150150
     151        memset(local_mask, 0, sizeof(local_mask));
     152
    151153        cr_server.head_spu->dispatch_table.GetPolygonStipple( local_mask );
    152154        crServerReturnValue( &(local_mask[0]), 128*sizeof(GLubyte) );
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_glsl.c

    r70601 r74890  
    182182    GLint i;
    183183
    184     if (n >= UINT32_MAX / sizeof(GLuint))
     184    if (n >= INT32_MAX / sizeof(GLuint))
    185185    {
    186186        crError("crServerDispatchDeleteProgramsARB: parameter 'n' is out of range");
     
    218218                                                                            GLboolean *residences)
    219219{
    220     GLboolean retval;
    221     GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
     220    GLboolean retval = GL_FALSE;
     221    GLboolean *res;
    222222    GLsizei i;
    223 
    224223    (void) residences;
    225224
     225    if (n >= INT32_MAX / sizeof(GLuint))
     226    {
     227        crError("crServerDispatchAreProgramsResidentNV: parameter 'n' is out of range");
     228        return GL_FALSE;
     229    }
     230
     231    res = (GLboolean *)crCalloc(n * sizeof(GLboolean));
     232
     233    if (!res) {
     234        crError("crServerDispatchAreProgramsResidentNV: out of memory");
     235        return GL_FALSE;
     236    }
     237
    226238    if (!cr_server.sharedTextureObjects) {
    227         GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
    228         for (i = 0; i < n; i++)
    229             programs2[i] = crServerTranslateProgramID(programs[i]);
    230         retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
    231         crFree(programs2);
     239        GLuint *programs2 = (GLuint *) crCalloc(n * sizeof(GLuint));
     240        if (programs2)
     241        {
     242            for (i = 0; i < n; i++)
     243                programs2[i] = crServerTranslateProgramID(programs[i]);
     244
     245            retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
     246            crFree(programs2);
     247        }
     248        else
     249        {
     250            crError("crServerDispatchAreProgramsResidentNV: out of memory");
     251        }
    232252    }
    233253    else {
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_lists.c

    r70601 r74890  
    230230crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
    231231{
    232     if (n >= UINT32_MAX / sizeof(GLuint))
     232    if (n >= INT32_MAX / sizeof(GLuint))
    233233    {
    234234        crError("crServerDispatchCallLists: parameter 'n' is out of range");
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.c

    r69390 r74890  
    2626    GLubyte local_storage[4096];
    2727    GLint bytes = 0;
     28    GLint cbType = 1; /* One byte by default. */
     29
     30    memset(local_storage, 0, sizeof(local_storage));
    2831
    2932    switch (type) {
    3033    case GL_BYTE:
    3134    case GL_UNSIGNED_BYTE:
    32          bytes = count * sizeof(GLbyte);
     35         cbType = sizeof(GLbyte);
    3336         break;
    3437    case GL_SHORT:
    3538    case GL_UNSIGNED_SHORT:
    36          bytes = count * sizeof(GLshort);
     39         cbType = sizeof(GLshort);
    3740         break;
    3841    case GL_INT:
    3942    case GL_UNSIGNED_INT:
    40          bytes = count * sizeof(GLint);
     43         cbType = sizeof(GLint);
    4144         break;
    4245    case GL_FLOAT:
    43          bytes = count * sizeof(GLfloat);
     46         cbType = sizeof(GLfloat);
    4447         break;
    4548    case GL_DOUBLE:
    46          bytes = count * sizeof(GLdouble);
     49         cbType = sizeof(GLdouble);
    4750         break;
    4851    default:
    4952         crError("Bad type in crServerDispatchGetChromiumParametervCR");
    5053    }
     54
     55    if (count < 0) /* 'GLsizei' is usually an 'int'. */
     56        count = 0;
     57    else if ((size_t)count > sizeof(local_storage) / cbType)
     58        count = sizeof(local_storage) / cbType;
     59
     60    bytes = count * cbType;
    5161
    5262    CRASSERT(bytes >= 0);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_occlude.c

    r69390 r74890  
    1414crServerDispatchGenQueriesARB(GLsizei n, GLuint *queries)
    1515{
    16         GLuint *local_queries = (GLuint *) crAlloc( n * sizeof(*local_queries) );
    17         (void) queries;
    18         cr_server.head_spu->dispatch_table.GenQueriesARB( n, local_queries );
    19         crServerReturnValue( local_queries, n * sizeof(*local_queries) );
    20         crFree( local_queries );
     16    GLuint *local_queries;
     17    (void) queries;
     18
     19    if (n >= INT32_MAX / sizeof(GLuint))
     20    {
     21        crError("crServerDispatchGenQueriesARB: parameter 'n' is out of range");
     22        return;
     23    }
     24
     25    local_queries = (GLuint *)crCalloc(n * sizeof(*local_queries));
     26
     27    if (!local_queries)
     28    {
     29        crError("crServerDispatchGenQueriesARB: out of memory");
     30        return;
     31    }
     32
     33    cr_server.head_spu->dispatch_table.GenQueriesARB( n, local_queries );
     34
     35    crServerReturnValue( local_queries, n * sizeof(*local_queries) );
     36    crFree( local_queries );
    2137}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_readpixels.c

    r69390 r74890  
    2020                           GLenum format, GLenum type, GLvoid *pixels)
    2121{
    22     CRMessageReadPixels *rp;
    2322    const GLint stride = READ_DATA( 24, GLint );
    2423    const GLint alignment = READ_DATA( 28, GLint );
     
    2726    const GLint bytes_per_row = READ_DATA( 40, GLint );
    2827    const GLint rowLength = READ_DATA( 44, GLint );
    29     const int msg_len = sizeof(*rp) + bytes_per_row * height;
    3028
    3129    CRASSERT(bytes_per_row > 0);
     
    4846#endif
    4947    {
     48        CRMessageReadPixels *rp;
     49        uint32_t msg_len;
     50
     51        if (bytes_per_row < 0 || bytes_per_row > UINT32_MAX / 8 || height > UINT32_MAX / 8)
     52        {
     53            crError("crServerDispatchReadPixels: parameters out of range");
     54            return;
     55        }
     56
     57        msg_len = sizeof(*rp) + (uint32_t)bytes_per_row * height;
     58
    5059        rp = (CRMessageReadPixels *) crAlloc( msg_len );
     60        if (!rp)
     61        {
     62            crError("crServerDispatchReadPixels: out of memory");
     63            return;
     64        }
    5165
    5266        /* Note: the ReadPixels data gets densely packed into the buffer
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_retval.py

    r69390 r74890  
    2525    {
    2626        CRMessageReadback *rb;
    27         int msg_len = sizeof( *rb ) + payload_len;
    28    
     27        int msg_len;
     28
    2929        /* Don't reply to client if we're loading VM snapshot*/
    3030        if (cr_server.bIsInLoadingState)
    3131            return;
    32    
     32
    3333        if (cr_server.curClient->conn->type == CR_FILE)
    3434        {
    3535            return;
    3636        }
    37    
     37
     38        if (payload_len >= INT32_MAX - sizeof( *rb ))
     39        {
     40            return;
     41        }
     42
     43        msg_len = sizeof( *rb ) + payload_len;
    3844        rb = (CRMessageReadback *) crAlloc( msg_len );
    39    
     45
    4046        rb->header.type = CR_MESSAGE_READBACK;
    4147        CRDBGPTR_PRINTRB(cr_server.curClient->conn->u32ClientID, &cr_server.writeback_ptr);
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_texture.c

    r70601 r74890  
    236236void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
    237237{
    238     GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
     238    GLuint *newTextures;
    239239    GLint i;
    240240
     241    if (n >= INT32_MAX / sizeof(GLuint))
     242    {
     243        crError("crServerDispatchPrioritizeTextures: parameter 'n' is out of range");
     244        return;
     245    }
     246
     247    newTextures = (GLuint *)crAlloc(n * sizeof(GLuint));
     248
    241249    if (!newTextures)
    242250    {
    243         crError("crServerDispatchDeleteTextures: out of memory");
     251        crError("crServerDispatchPrioritizeTextures: out of memory");
    244252        return;
    245253    }
     
    271279                                    GLboolean *residences)
    272280{
    273     GLboolean retval;
     281    GLboolean retval = GL_FALSE;
    274282    GLsizei i;
    275     GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
    276     GLuint *textures2 = (GLuint *) crAlloc(n * sizeof(GLuint));
    277 
     283    GLboolean *res;
     284    GLuint *textures2;
    278285    (void) residences;
    279286
     287    if (n >= INT32_MAX / sizeof(GLuint))
     288    {
     289        crError("crServerDispatchAreTexturesResident: parameter 'n' is out of range");
     290        return GL_FALSE;
     291    }
     292
     293    res = (GLboolean *)crCalloc(n * sizeof(GLboolean));
     294    if (!res)
     295    {
     296        crError("crServerDispatchAreTexturesResident: out of memory");
     297        return GL_FALSE;
     298    }
     299
     300    textures2 = (GLuint *)crAlloc(n * sizeof(GLuint));
     301
     302    if (!textures2)
     303    {
     304        crError("crServerDispatchAreTexturesResident: out of memory");
     305        crFree(res);
     306        return GL_FALSE;
     307    }
     308
    280309    for (i = 0; i < n; i++)
    281310    {
  • trunk/src/VBox/HostServices/SharedOpenGL/dlm/dlm_lists.c

    r69500 r74890  
    353353
    354354    crDebug("DLM: CallLists(%d, %u, %p).", n, type, lists);
     355   
     356    if (n >= INT32_MAX / sizeof(GLuint))
     357    {
     358        crError("crDLMCallLists: parameter 'n' is out of range");
     359        return;
     360    }
    355361
    356362    if (pListState)
  • trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack_map.c

    r69390 r74890  
    88#include "cr_error.h"
    99#include "cr_mem.h"
     10#include "state/cr_limits.h"
    1011
    1112
    1213void crUnpackMap2d(void)
    1314{
    14         GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
    15         GLdouble u1 = READ_DOUBLE(sizeof(int) + 4);
    16         GLdouble u2 = READ_DOUBLE(sizeof(int) + 12);
    17         GLint ustride = READ_DATA(sizeof(int) + 20, GLint);
    18         GLint uorder = READ_DATA(sizeof(int) + 24, GLint);
    19         GLdouble v1 = READ_DOUBLE(sizeof(int) + 28);
    20         GLdouble v2 = READ_DOUBLE(sizeof(int) + 36);
    21         GLint vstride = READ_DATA(sizeof(int) + 44, GLint);
    22         GLint vorder = READ_DATA(sizeof(int) + 48, GLint);
     15    GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
     16    GLdouble u1 = READ_DOUBLE(sizeof(int) + 4);
     17    GLdouble u2 = READ_DOUBLE(sizeof(int) + 12);
     18    GLint ustride = READ_DATA(sizeof(int) + 20, GLint);
     19    GLint uorder = READ_DATA(sizeof(int) + 24, GLint);
     20    GLdouble v1 = READ_DOUBLE(sizeof(int) + 28);
     21    GLdouble v2 = READ_DOUBLE(sizeof(int) + 36);
     22    GLint vstride = READ_DATA(sizeof(int) + 44, GLint);
     23    GLint vorder = READ_DATA(sizeof(int) + 48, GLint);
     24    GLdouble *points = DATA_POINTER(sizeof(int) + 52, GLdouble);
     25    GLint cbMax;
    2326
    24         int n_points = READ_DATA(0, int) - (sizeof(int) + 52);
    25         GLdouble *points;
     27    if (uorder < 1 || uorder > CR_MAX_EVAL_ORDER ||
     28        vorder < 1 || vorder > CR_MAX_EVAL_ORDER ||
     29        ustride < 1 || ustride > INT32_MAX / (ssize_t)sizeof(double) / uorder / 8 ||
     30        vstride < 1 || vstride > INT32_MAX / (ssize_t)sizeof(double) / vorder / 8 )
     31    {
     32        crError("crUnpackMap2d: parameters out of range");
     33        return;
     34    }
    2635
    27         if (n_points & 0x7)
    28                 crError("crUnpackMap2d: n_points=%d, expected multiple of 8\n", n_points);
    29         points = (GLdouble *) crAlloc(n_points);
    30         crMemcpy(points, DATA_POINTER(sizeof(int) + 52, GLdouble), n_points);
     36    cbMax = (ustride * uorder + vstride * vorder) * sizeof(double);
     37    if (!DATA_POINTER_CHECK(cbMax - 1))
     38    {
     39        crError("crUnpackMap2d: parameters out of range");
     40        return;
     41    }
    3142
    32         cr_unpackDispatch.Map2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder,
    33                          points);
    34         crFree(points);
     43    cr_unpackDispatch.Map2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
    3544
    36         INCR_VAR_PTR();
     45    INCR_VAR_PTR();
    3746}
    3847
    3948void crUnpackMap2f(void)
    4049{
    41         GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
    42         GLfloat u1 = READ_DATA(sizeof(int) + 4, GLfloat);
    43         GLfloat u2 = READ_DATA(sizeof(int) + 8, GLfloat);
    44         GLint ustride = READ_DATA(sizeof(int) + 12, GLint);
    45         GLint uorder = READ_DATA(sizeof(int) + 16, GLint);
    46         GLfloat v1 = READ_DATA(sizeof(int) + 20, GLfloat);
    47         GLfloat v2 = READ_DATA(sizeof(int) + 24, GLfloat);
    48         GLint vstride = READ_DATA(sizeof(int) + 28, GLint);
    49         GLint vorder = READ_DATA(sizeof(int) + 32, GLint);
    50         GLfloat *points = DATA_POINTER(sizeof(int) + 36 , GLfloat);
     50    GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
     51    GLfloat u1 = READ_DATA(sizeof(int) + 4, GLfloat);
     52    GLfloat u2 = READ_DATA(sizeof(int) + 8, GLfloat);
     53    GLint ustride = READ_DATA(sizeof(int) + 12, GLint);
     54    GLint uorder = READ_DATA(sizeof(int) + 16, GLint);
     55    GLfloat v1 = READ_DATA(sizeof(int) + 20, GLfloat);
     56    GLfloat v2 = READ_DATA(sizeof(int) + 24, GLfloat);
     57    GLint vstride = READ_DATA(sizeof(int) + 28, GLint);
     58    GLint vorder = READ_DATA(sizeof(int) + 32, GLint);
     59    GLfloat *points = DATA_POINTER(sizeof(int) + 36, GLfloat);
     60    GLint cbMax;
    5161
    52         cr_unpackDispatch.Map2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder,
    53                          points);
    54         INCR_VAR_PTR();
     62    if (uorder < 1 || uorder > CR_MAX_EVAL_ORDER ||
     63        vorder < 1 || vorder > CR_MAX_EVAL_ORDER ||
     64        ustride < 1 || ustride > INT32_MAX / (ssize_t)sizeof(float) / uorder / 8 ||
     65        vstride < 1 || vstride > INT32_MAX / (ssize_t)sizeof(float) / vorder / 8)
     66    {
     67        crError("crUnpackMap2d: parameters out of range");
     68        return;
     69    }
     70
     71    cbMax = (ustride * uorder + vstride * vorder) * sizeof(float);
     72    if (!DATA_POINTER_CHECK(cbMax - 1))
     73    {
     74        crError("crUnpackMap2f: parameters out of range");
     75        return;
     76    }
     77
     78    cr_unpackDispatch.Map2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
     79
     80    INCR_VAR_PTR();
    5581}
    5682
    5783void crUnpackMap1d(void)
    5884{
    59         GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
    60         GLdouble u1 = READ_DOUBLE(sizeof(int) + 4);
    61         GLdouble u2 = READ_DOUBLE(sizeof(int) + 12);
    62         GLint stride = READ_DATA(sizeof(int) + 20, GLint);
    63         GLint order = READ_DATA(sizeof(int) + 24, GLint);
     85    GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
     86    GLdouble u1 = READ_DOUBLE(sizeof(int) + 4);
     87    GLdouble u2 = READ_DOUBLE(sizeof(int) + 12);
     88    GLint stride = READ_DATA(sizeof(int) + 20, GLint);
     89    GLint order = READ_DATA(sizeof(int) + 24, GLint);
     90    GLdouble *points = DATA_POINTER(sizeof(int) + 28, GLdouble);
     91    GLint cbMax;
    6492
    65         int n_points = READ_DATA(0, int) - (sizeof(int) + 28);
    66         GLdouble *points;
     93    if (order < 1 || order > CR_MAX_EVAL_ORDER ||
     94        stride < 1 || stride > INT32_MAX / (ssize_t)sizeof(double) / order / 8)
     95    {
     96        crError("crUnpackMap1d: parameters out of range");
     97        return;
     98    }
    6799
    68         if (n_points & 0x7)
    69                 crError("crUnpackMap1d: n_points=%d, expected multiple of 8\n", n_points);
    70         points = (GLdouble *) crAlloc(n_points);
    71         crMemcpy(points, DATA_POINTER(sizeof(int) + 28, GLdouble), n_points);
    72        
    73         cr_unpackDispatch.Map1d(target, u1, u2, stride, order, points);
    74         crFree(points);
     100    cbMax = stride * order * sizeof(double);
     101    if (!DATA_POINTER_CHECK(cbMax - 1))
     102    {
     103        crError("crUnpackMap1d: parameters out of range");
     104        return;
     105    }
    75106
    76         INCR_VAR_PTR();
     107    cr_unpackDispatch.Map1d(target, u1, u2, stride, order, points);
     108
     109    INCR_VAR_PTR();
    77110}
    78111
    79112void crUnpackMap1f(void)
    80113{
    81         GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
    82         GLfloat u1 = READ_DATA(sizeof(int) + 4, GLfloat);
    83         GLfloat u2 = READ_DATA(sizeof(int) + 8, GLfloat);
    84         GLint stride = READ_DATA(sizeof(int) + 12, GLint);
    85         GLint order = READ_DATA(sizeof(int) + 16, GLint);
    86         GLfloat *points = DATA_POINTER(sizeof(int) + 20, GLfloat);
     114    GLenum target = READ_DATA(sizeof(int) + 0, GLenum);
     115    GLfloat u1 = READ_DATA(sizeof(int) + 4, GLfloat);
     116    GLfloat u2 = READ_DATA(sizeof(int) + 8, GLfloat);
     117    GLint stride = READ_DATA(sizeof(int) + 12, GLint);
     118    GLint order = READ_DATA(sizeof(int) + 16, GLint);
     119    GLfloat *points = DATA_POINTER(sizeof(int) + 20, GLfloat);
     120    GLint cbMax;
    87121
    88         cr_unpackDispatch.Map1f(target, u1, u2, stride, order, points);
    89         INCR_VAR_PTR();
     122    if (order < 1 || order > CR_MAX_EVAL_ORDER ||
     123        stride < 1 || stride > INT32_MAX / (ssize_t)sizeof(float) / order / 8)
     124    {
     125        crError("crUnpackMap1f: parameters out of range");
     126        return;
     127    }
     128
     129    cbMax = stride * order * sizeof(float);
     130    if (!DATA_POINTER_CHECK(cbMax - 1))
     131    {
     132        crError("crUnpackMap1f: parameters out of range");
     133        return;
     134    }
     135
     136    cr_unpackDispatch.Map1f(target, u1, u2, stride, order, points);
     137    INCR_VAR_PTR();
    90138}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette