Skip to content

Commit 4df05a7

Browse files
Hana Ashour (Si-Vision)HanaMAshour
authored andcommitted
tinystdio: Handled invalid sequence of characters
Handled invalid hexadecimal sequence passed to the vfscanf function by using "isxdigit" to check for the full hex range and detect invalid entry. Handled if the exponent in the floating point is a valid entry by using "isdigit" Signed-off-by: Hana Ashour <[email protected]>
1 parent 4e2fa5b commit 4df05a7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

newlib/libc/tinystdio/conv_flt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,12 @@ conv_flt (FLT_STREAM *stream, FLT_CONTEXT *context, width_t width, void *addr, u
394394
if (!isdigit (edig))
395395
{
396396
scanf_ungetc(edig, stream, context);
397-
if (esign != EOF)
398-
scanf_ungetc(esign, stream, context);
397+
if (esign != EOF) {
398+
esign = scanf_getc (stream, context);
399+
if(!isdigit (esign))
400+
return 0;
401+
scanf_ungetc(edig, stream, context);
402+
}
399403
goto no_exp;
400404
}
401405

newlib/libc/tinystdio/vfscanf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ conv_int (FILE *stream, scanf_context_t *context, width_t width, void *addr, uin
279279
base = 16;
280280
if (!--width || IS_EOF(i = scanf_getc (stream, context)))
281281
goto putval;
282+
if(!isxdigit(i))
283+
goto err;
282284
#ifdef _NEED_IO_PERCENT_B
283285
} else if (i == 'b' && base <= 2) {
284286
base = 2;

0 commit comments

Comments
 (0)