Skip to content
Permalink
Browse files Browse the repository at this point in the history
Removed a potential buffer overflow crash in GmfOpenMesh and debugged…
… the test_libmeshb_block_pipeline.f that crashed
  • Loading branch information
LoicMarechal committed Jan 7, 2022
1 parent 0f200ec commit 8cd68c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions 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'
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions sources/libmeshb7.c
Expand Up @@ -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 */
/* */
/*----------------------------------------------------------------------------*/

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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]))
Expand Down

0 comments on commit 8cd68c5

Please sign in to comment.