Use-after-free when saving Qt message history #996

Possibly resolve #996
This commit is contained in:
nhmall
2023-03-10 11:27:11 -05:00
parent 62476fe101
commit b61f55f0e4
2 changed files with 5 additions and 3 deletions

View File

@@ -100,9 +100,10 @@ const char * NetHackQtMessageWindow::GetStr(bool init)
QListWidgetItem *item = list->item(currgetmsg++);
if (item) {
QString str = item->text();
const char *result = str.toLatin1().constData();
//raw_printf("getstr[%d]='%s'", currgetmsg, result);
return result;
if (str.toLatin1().length() < (int) sizeof historybuf - 1) {
return strcpy(historybuf, str.toLatin1().constData());
//raw_printf("getstr[%d]='%s'", currgetmsg, result);
}
}
return NULL;
}

View File

@@ -42,6 +42,7 @@ private:
bool changed;
int currgetmsg;
NetHackQtMapWindow2* map;
char historybuf[BUFSZ];
private slots:
void updateFont();