Skip to content

Commit 8cd68c5

Browse files
committed
Removed a potential buffer overflow crash in GmfOpenMesh and debugged the test_libmeshb_block_pipeline.f that crashed
1 parent 0f200ec commit 8cd68c5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Diff for: examples/test_libmeshb_block_pipeline.f

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
c libmeshb example : transform a quadrilateral mesh into a triangular one
2+
c libmeshb example: transform a quadrilateral mesh into a triangular one
33
c using fast block transfer and pipelined post processing
44

55
include 'libmeshb7.ins'
@@ -39,14 +39,15 @@
3939

4040
c Read the vertices
4141
res = gmfgetblock(InpMsh, GmfVertices, 1_8, NmbVer,
42-
+ movver, 1, VerTab,
42+
+ 0, %val(0), movver, 1, VerTab,
4343
+ GmfDouble, VerTab(1,1), VerTab(1,2),
4444
+ GmfDouble, VerTab(2,1), VerTab(2,2),
4545
+ GmfDouble, VerTab(3,1), VerTab(3,2),
4646
+ GmfInt, RefTab(1), RefTab(2))
4747

4848
c Read the quads
49-
res = gmfgetblock(InpMsh, GmfQuadrilaterals, 1_8, NmbQad,0,
49+
res = gmfgetblock(InpMsh, GmfQuadrilaterals, 1_8, NmbQad,
50+
+ 0, %val(0), %val(0),
5051
+ GmfInt, QadTab(1,1), QadTab(1,2),
5152
+ GmfInt, QadTab(2,1), QadTab(2,2),
5253
+ GmfInt, QadTab(3,1), QadTab(3,2),
@@ -79,7 +80,7 @@
7980
c Write the triangles
8081
res = gmfsetkwd(OutMsh, GmfTriangles, 2*NmbQad, 0, 0)
8182
res = gmfsetblock(OutMsh, GmfTriangles, 1_8, 2*NmbQad,
82-
+ 0,%val(0),%val(0),
83+
+ 0,%val(0),
8384
+ qad2tri, 2, QadTab, TriTab,
8485
+ GmfInt, TriTab(1,1), TriTab(1,2),
8586
+ GmfInt, TriTab(2,1), TriTab(2,2),

Diff for: sources/libmeshb7.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
/*----------------------------------------------------------------------------*/
44
/* */
5-
/* LIBMESHB V7.61 */
5+
/* LIBMESHB V7.62 */
66
/* */
77
/*----------------------------------------------------------------------------*/
88
/* */
99
/* Description: handles .meshb file format I/O */
1010
/* Author: Loic MARECHAL */
1111
/* Creation date: dec 09 1999 */
12-
/* Last modification: sep 27 2021 */
12+
/* Last modification: jan 07 2022 */
1313
/* */
1414
/*----------------------------------------------------------------------------*/
1515

@@ -655,7 +655,7 @@ int64_t GmfOpenMesh(const char *FilNam, int mod, ...)
655655

656656
do
657657
{
658-
res = fscanf(msh->hdl, "%s", str);
658+
res = fscanf(msh->hdl, "%100s", str);
659659
}while( (res != EOF) && strcmp(str, "MeshVersionFormatted") );
660660

661661
if(res == EOF)
@@ -668,7 +668,7 @@ int64_t GmfOpenMesh(const char *FilNam, int mod, ...)
668668

669669
do
670670
{
671-
res = fscanf(msh->hdl, "%s", str);
671+
res = fscanf(msh->hdl, "%100s", str);
672672
}while( (res != EOF) && strcmp(str, "Dimension") );
673673

674674
if(res == EOF)
@@ -2539,7 +2539,7 @@ static int ScaKwdTab(GmfMshSct *msh)
25392539
if(msh->typ & Asc)
25402540
{
25412541
// Scan each string in the file until the end
2542-
while(fscanf(msh->hdl, "%s", str) != EOF)
2542+
while(fscanf(msh->hdl, "%100s", str) != EOF)
25432543
{
25442544
// Fast test in order to reject quickly the numeric values
25452545
if(isalpha(str[0]))

0 commit comments

Comments
 (0)