star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit 53086f69c549aac9101683b280f55267f446b5a5
parent e6e9676cb13b11b9f0064713530a9b37f1139fc1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  1 Jul 2016 10:14:47 +0200

Fix an issue in the setup of a mesh

A memory corruption may occur if the usage of a vertex data was not
valid, i.e. its value was not less than to S3D_ATTRIBS_COUNT__

Diffstat:
Msrc/s3d_mesh.c | 5++++-
Msrc/test_s3d_shape.c | 2+-
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/s3d_mesh.c b/src/s3d_mesh.c @@ -478,7 +478,10 @@ mesh_setup_indexed_vertices iattr = 0; has_position = 0; FOR_EACH(iattr, 0, nattribs) { - ASSERT(attribs[iattr].usage < S3D_ATTRIBS_COUNT__); + if((unsigned)attribs[iattr].usage >= S3D_ATTRIBS_COUNT__) { /* Invalid usage */ + res = RES_BAD_ARG; + goto error; + } if(attribs[iattr].get == S3D_KEEP) { const enum s3d_attrib_usage attr_usage = attribs[iattr].usage; const enum s3d_type type = attribs[iattr].type; diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c @@ -178,7 +178,7 @@ main(int argc, char** argv) attribs[0] = S3D_VERTEX_DATA_NULL; CHECK(s3d_mesh_setup_indexed_vertices - (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, 0, data), RES_BAD_ARG); + (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, 1, data), RES_BAD_ARG); attribs[0].type = S3D_FLOAT3; attribs[0].usage = S3D_POSITION;