Skip to content

Commit d775fa0

Browse files
authored
Restrict fscanf %s in h5import (#5887)
A couple of places in the h5import.c code use fscanf with %s to read strings into a fixed-size buffer without restricting the number of characters, which could lead to a stack buffer overflow. This fix restricts the number of characters that can be read to the size of the buffer.
1 parent 1f52fdc commit d775fa0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/src/h5import/h5import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ readIntegerData(FILE *strm, struct Input *in)
586586
switch (in->inputClass) {
587587
case 0: /* TEXTIN */
588588
for (i = 0; i < len; i++, in64++) {
589-
if (fscanf(strm, "%s", buffer) < 1) {
589+
if (fscanf(strm, "%255s", buffer) < 1) {
590590
(void)fprintf(rawerrorstream, "%s", err1);
591591
return (-1);
592592
}
@@ -753,7 +753,7 @@ readUIntegerData(FILE *strm, struct Input *in)
753753
switch (in->inputClass) {
754754
case 6: /* TEXTUIN */
755755
for (i = 0; i < len; i++, in64++) {
756-
if (fscanf(strm, "%s", buffer) < 1) {
756+
if (fscanf(strm, "%255s", buffer) < 1) {
757757
(void)fprintf(rawerrorstream, "%s", err1);
758758
return (-1);
759759
}

0 commit comments

Comments
 (0)