From 8cd68c54e0647c0030ae4506a225ad4a2655c316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mar=C3=A9chal?= Date: Fri, 7 Jan 2022 14:25:30 +0100 Subject: [PATCH] Removed a potential buffer overflow crash in GmfOpenMesh and debugged the test_libmeshb_block_pipeline.f that crashed --- examples/test_libmeshb_block_pipeline.f | 9 +++++---- sources/libmeshb7.c | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/test_libmeshb_block_pipeline.f b/examples/test_libmeshb_block_pipeline.f index 940d634..e54a85c 100644 --- a/examples/test_libmeshb_block_pipeline.f +++ b/examples/test_libmeshb_block_pipeline.f @@ -1,5 +1,5 @@ -c libmeshb example : transform a quadrilateral mesh into a triangular one +c libmeshb example: transform a quadrilateral mesh into a triangular one c using fast block transfer and pipelined post processing include 'libmeshb7.ins' @@ -39,14 +39,15 @@ c Read the vertices res = gmfgetblock(InpMsh, GmfVertices, 1_8, NmbVer, - + movver, 1, VerTab, + + 0, %val(0), movver, 1, VerTab, + GmfDouble, VerTab(1,1), VerTab(1,2), + GmfDouble, VerTab(2,1), VerTab(2,2), + GmfDouble, VerTab(3,1), VerTab(3,2), + GmfInt, RefTab(1), RefTab(2)) c Read the quads - res = gmfgetblock(InpMsh, GmfQuadrilaterals, 1_8, NmbQad,0, + res = gmfgetblock(InpMsh, GmfQuadrilaterals, 1_8, NmbQad, + + 0, %val(0), %val(0), + GmfInt, QadTab(1,1), QadTab(1,2), + GmfInt, QadTab(2,1), QadTab(2,2), + GmfInt, QadTab(3,1), QadTab(3,2), @@ -79,7 +80,7 @@ c Write the triangles res = gmfsetkwd(OutMsh, GmfTriangles, 2*NmbQad, 0, 0) res = gmfsetblock(OutMsh, GmfTriangles, 1_8, 2*NmbQad, - + 0,%val(0),%val(0), + + 0,%val(0), + qad2tri, 2, QadTab, TriTab, + GmfInt, TriTab(1,1), TriTab(1,2), + GmfInt, TriTab(2,1), TriTab(2,2), diff --git a/sources/libmeshb7.c b/sources/libmeshb7.c index 8aab88e..a808b4e 100644 --- a/sources/libmeshb7.c +++ b/sources/libmeshb7.c @@ -2,14 +2,14 @@ /*----------------------------------------------------------------------------*/ /* */ -/* LIBMESHB V7.61 */ +/* LIBMESHB V7.62 */ /* */ /*----------------------------------------------------------------------------*/ /* */ /* Description: handles .meshb file format I/O */ /* Author: Loic MARECHAL */ /* Creation date: dec 09 1999 */ -/* Last modification: sep 27 2021 */ +/* Last modification: jan 07 2022 */ /* */ /*----------------------------------------------------------------------------*/ @@ -655,7 +655,7 @@ int64_t GmfOpenMesh(const char *FilNam, int mod, ...) do { - res = fscanf(msh->hdl, "%s", str); + res = fscanf(msh->hdl, "%100s", str); }while( (res != EOF) && strcmp(str, "MeshVersionFormatted") ); if(res == EOF) @@ -668,7 +668,7 @@ int64_t GmfOpenMesh(const char *FilNam, int mod, ...) do { - res = fscanf(msh->hdl, "%s", str); + res = fscanf(msh->hdl, "%100s", str); }while( (res != EOF) && strcmp(str, "Dimension") ); if(res == EOF) @@ -2539,7 +2539,7 @@ static int ScaKwdTab(GmfMshSct *msh) if(msh->typ & Asc) { // Scan each string in the file until the end - while(fscanf(msh->hdl, "%s", str) != EOF) + while(fscanf(msh->hdl, "%100s", str) != EOF) { // Fast test in order to reject quickly the numeric values if(isalpha(str[0]))