Sanitize textprompts and cutscenes

This commit is contained in:
GenericHeroGuy 2025-06-25 22:49:42 +02:00
parent 2ff383a248
commit e987c96651
3 changed files with 24 additions and 15 deletions

View file

@ -1353,7 +1353,8 @@ static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum)
if (fastcmp(word+4, "NAME"))
{
strncpy(cutscenes[num]->scene[scenenum].picname[picid], word2, 8);
strncpy(cutscenes[num]->scene[scenenum].picname[picid], word2, SHORTNAMELEN);
cutscenes[num]->scene[scenenum].picname[picid][SHORTNAMELEN] = '\0';
}
else if (fastcmp(word+4, "HIRES"))
{
@ -1595,7 +1596,8 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
for (picid = 0; picid < MAX_PROMPT_PICS; picid++)
{
strncpy(textprompts[num]->page[pagenum].picname[picid], textprompts[num]->page[metapagenum].picname[picid], 8);
strncpy(textprompts[num]->page[pagenum].picname[picid], textprompts[num]->page[metapagenum].picname[picid], SHORTNAMELEN);
textprompts[num]->page[pagenum].picname[picid][SHORTNAMELEN] = '\0';
textprompts[num]->page[pagenum].pichires[picid] = textprompts[num]->page[metapagenum].pichires[picid];
textprompts[num]->page[pagenum].picduration[picid] = textprompts[num]->page[metapagenum].picduration[picid];
textprompts[num]->page[pagenum].xcoord[picid] = textprompts[num]->page[metapagenum].xcoord[picid];
@ -1615,7 +1617,8 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
if (fastcmp(word+4, "NAME"))
{
strncpy(textprompts[num]->page[pagenum].picname[picid], word2, 8);
strncpy(textprompts[num]->page[pagenum].picname[picid], word2, SHORTNAMELEN);
textprompts[num]->page[pagenum].picname[picid][SHORTNAMELEN] = '\0';
}
else if (fastcmp(word+4, "HIRES"))
{
@ -1677,7 +1680,10 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
*textprompts[num]->page[pagenum].name = '\0';
}
else if (fastcmp(word, "ICON"))
strncpy(textprompts[num]->page[pagenum].iconname, word2, 8);
{
strncpy(textprompts[num]->page[pagenum].iconname, word2, SHORTNAMELEN);
textprompts[num]->page[pagenum].iconname[SHORTNAMELEN] = '\0';
}
else if (fastcmp(word, "ICONALIGN"))
textprompts[num]->page[pagenum].rightside = (i || word2[0] == 'R');
else if (fastcmp(word, "ICONFLIP"))
@ -1745,7 +1751,8 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
UINT8 metapagenum = usi - 1;
strncpy(textprompts[num]->page[pagenum].name, textprompts[num]->page[metapagenum].name, 32);
strncpy(textprompts[num]->page[pagenum].iconname, textprompts[num]->page[metapagenum].iconname, 8);
strncpy(textprompts[num]->page[pagenum].iconname, textprompts[num]->page[metapagenum].iconname, SHORTNAMELEN);
textprompts[num]->page[pagenum].iconname[SHORTNAMELEN] = '\0';
textprompts[num]->page[pagenum].rightside = textprompts[num]->page[metapagenum].rightside;
textprompts[num]->page[pagenum].iconflip = textprompts[num]->page[metapagenum].iconflip;
textprompts[num]->page[pagenum].lines = textprompts[num]->page[metapagenum].lines;

View file

@ -204,10 +204,12 @@ extern UINT16 skincolor_redteam, skincolor_blueteam, skincolor_redring, skincolo
extern boolean exitfadestarted;
#define SHORTNAMELEN 8
struct scene_t
{
UINT8 numpics;
char picname[8][8];
char picname[8][SHORTNAMELEN+1];
UINT8 pichires[8];
char *text;
UINT16 xcoord[8];
@ -251,7 +253,7 @@ struct textpage_t
UINT8 picmode; // sequence mode after displaying last pic, 0 = persist, 1 = loop, 2 = destroy
UINT8 pictoloop; // if picmode == loop, which pic to loop to?
UINT8 pictostart; // initial pic number to show
char picname[MAX_PROMPT_PICS][8];
char picname[MAX_PROMPT_PICS][SHORTNAMELEN+1];
UINT8 pichires[MAX_PROMPT_PICS];
UINT16 xcoord[MAX_PROMPT_PICS]; // gfx
UINT16 ycoord[MAX_PROMPT_PICS]; // gfx
@ -263,7 +265,7 @@ struct textpage_t
char tag[33]; // page tag
char name[34]; // narrator name, extra char for color
char iconname[8]; // narrator icon lump
char iconname[SHORTNAMELEN+1]; // narrator icon lump
boolean rightside; // narrator side, false = left, true = right
boolean iconflip; // narrator flip icon horizontally
UINT8 hidehud; // hide hud, 0 = show all, 1 = hide depending on prompt position (top/bottom), 2 = hide all

View file

@ -1842,10 +1842,10 @@ void F_CutsceneDrawer(void)
{
if (cutscenes[cutnum]->scene[scenenum].pichires[picnum])
V_DrawSmallScaledPatch(picxpos, picypos, 0,
W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
W_CachePatchLongName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
else
V_DrawScaledPatch(picxpos,picypos, 0,
W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
W_CachePatchLongName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
}
if (dofadenow && rendermode != render_none)
@ -1928,7 +1928,7 @@ static void F_GetPageTextGeometry(UINT8 *pagelines, boolean *rightside, INT32 *b
// reuse:
// cutnum -> promptnum
// scenenum -> pagenum
lumpnum_t iconlump = W_CheckNumForName(textprompts[cutnum]->page[scenenum].iconname);
lumpnum_t iconlump = W_CheckNumForLongName(textprompts[cutnum]->page[scenenum].iconname);
*pagelines = textprompts[cutnum]->page[scenenum].lines ? textprompts[cutnum]->page[scenenum].lines : 4;
*rightside = (iconlump != LUMPERROR && textprompts[cutnum]->page[scenenum].rightside);
@ -2303,7 +2303,7 @@ void F_TextPromptDrawer(void)
if (!promptactive)
return;
iconlump = W_CheckNumForName(textprompts[cutnum]->page[scenenum].iconname);
iconlump = W_CheckNumForLongName(textprompts[cutnum]->page[scenenum].iconname);
F_GetPageTextGeometry(&pagelines, &rightside, &boxh, &texth, &texty, &namey, &chevrony, &textx, &textr);
// Draw gfx first
@ -2311,10 +2311,10 @@ void F_TextPromptDrawer(void)
{
if (textprompts[cutnum]->page[scenenum].pichires[picnum])
V_DrawSmallScaledPatch(picxpos, picypos, 0,
W_CachePatchName(textprompts[cutnum]->page[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
W_CachePatchLongName(textprompts[cutnum]->page[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
else
V_DrawScaledPatch(picxpos,picypos, 0,
W_CachePatchName(textprompts[cutnum]->page[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
W_CachePatchLongName(textprompts[cutnum]->page[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY));
}
// Draw background
@ -2324,7 +2324,7 @@ void F_TextPromptDrawer(void)
if (iconlump != LUMPERROR)
{
INT32 iconx, icony, scale, scaledsize;
patch = W_CachePatchName(textprompts[cutnum]->page[scenenum].iconname, PU_PATCH_LOWPRIORITY);
patch = W_CachePatchLongName(textprompts[cutnum]->page[scenenum].iconname, PU_PATCH_LOWPRIORITY);
// scale and center
if (patch->width > patch->height)