Skip to content

Commit 3bff8ab

Browse files
authored
kernel: make FormatOutput handle %g with null pointer (#6446)
In case someone uses '%g' in a format string but fails to provide a matching argument. Moreover, make sure we don't use `arg2` more then once.
1 parent 0eed36b commit 3bff8ab

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/io.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,6 @@ static Obj FuncALL_KEYWORDS(Obj self)
15131513
** '%g' the corresponding argument is the address of a T_STRING string
15141514
** object which is printed. This is similar to using '%s' to print
15151515
** CSTR_STRING(arg), but is safe during garbage collection.
1516-
** '%G' the corresponding argument is the address of an Obj which points
1517-
** to a string in STRING_REP format which is printed in '%S' format
15181516
** '%C' the corresponding argument is the address of an Obj which points
15191517
** to a string in STRING_REP format which is printed with C escapes
15201518
** '%d' the corresponding argument is a signed integer, which is printed.
@@ -1556,7 +1554,7 @@ static inline void FormatOutput(
15561554
}
15571555

15581556
// handle the case of a missing argument
1559-
if (arg1 == 0 && (*p == 's' || *p == 'S' || *p == 'C' || *p == 'I')) {
1557+
if (arg1 == 0 && (*p == 's' || *p == 'g' || *p == 'C' || *p == 'I')) {
15601558
put_a_char(state, '<');
15611559
put_a_char(state, 'n');
15621560
put_a_char(state, 'u');
@@ -1566,6 +1564,7 @@ static inline void FormatOutput(
15661564

15671565
// on to the next argument
15681566
arg1 = arg2;
1567+
arg2 = 0;
15691568
}
15701569

15711570
// '%d' print an integer
@@ -1591,6 +1590,7 @@ static inline void FormatOutput(
15911590

15921591
// on to the next argument
15931592
arg1 = arg2;
1593+
arg2 = 0;
15941594
}
15951595

15961596
// '%s' or '%g' print a string
@@ -1650,6 +1650,7 @@ static inline void FormatOutput(
16501650

16511651
// on to the next argument
16521652
arg1 = arg2;
1653+
arg2 = 0;
16531654
}
16541655

16551656
// '%C' print a string with the necessary C escapes
@@ -1699,6 +1700,7 @@ static inline void FormatOutput(
16991700

17001701
// on to the next argument
17011702
arg1 = arg2;
1703+
arg2 = 0;
17021704
}
17031705

17041706
// '%I' print an identifier
@@ -1742,12 +1744,14 @@ static inline void FormatOutput(
17421744

17431745
// on to the next argument
17441746
arg1 = arg2;
1747+
arg2 = 0;
17451748
}
17461749

17471750
// '%c' print a character
17481751
else if ( *p == 'c' ) {
17491752
put_a_char(state, (Char)arg1);
17501753
arg1 = arg2;
1754+
arg2 = 0;
17511755
}
17521756

17531757
// '%%' print a '%' character

0 commit comments

Comments
 (0)