Limit number of string format elements to compile.

Reported by pwnhacker0x18. #1203
This commit is contained in:
Mike Pall 2024-05-25 16:22:39 +02:00
parent a6386bdabe
commit 4fc48c50fe

View File

@ -1005,6 +1005,7 @@ static void recff_format(jit_State *J, RecordFFData *rd, TRef hdr, int sbufx)
GCstr *fmt = argv2str(J, &rd->argv[arg]); GCstr *fmt = argv2str(J, &rd->argv[arg]);
FormatState fs; FormatState fs;
SFormat sf; SFormat sf;
int nfmt = 0;
/* Specialize to the format string. */ /* Specialize to the format string. */
emitir(IRTG(IR_EQ, IRT_STR), trfmt, lj_ir_kstr(J, fmt)); emitir(IRTG(IR_EQ, IRT_STR), trfmt, lj_ir_kstr(J, fmt));
lj_strfmt_init(&fs, strdata(fmt), fmt->len); lj_strfmt_init(&fs, strdata(fmt), fmt->len);
@ -1082,6 +1083,7 @@ static void recff_format(jit_State *J, RecordFFData *rd, TRef hdr, int sbufx)
recff_nyiu(J, rd); recff_nyiu(J, rd);
return; return;
} }
if (++nfmt > 100) lj_trace_err(J, LJ_TRERR_TRACEOV);
} }
if (sbufx) { if (sbufx) {
emitir(IRT(IR_USE, IRT_NIL), tr, 0); emitir(IRT(IR_USE, IRT_NIL), tr, 0);