dtstyle: fix bugs preventing SM save from working properly

All of the dtstyle session save routines used sprintf/snprintf whereby
the destination buffer was also a source buffer, like so:

snprintf(bufr, sizeof(style.tmpBigStr), "%s*Fonts.x: %d\n", bufr, x);
         ^^^^                            ^^                 ^^^^

That results in undefined behavior, which mainly meant missing or
currupted XRM resources being saved in the session file for dtstyle.
This commit is contained in:
Jon Trulson
2022-02-26 15:09:43 -07:00
parent a52f988e47
commit 383b5e4b59
14 changed files with 124 additions and 108 deletions

View File

@@ -1178,7 +1178,7 @@ saveI18n(
{
Position x,y;
Dimension width, height;
char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
char bufr[1024]; /* size=[1024], make bigger if needed */
XmVendorShellExtObject vendorExt;
XmWidgetExtData extData;
@@ -1189,6 +1189,8 @@ saveI18n(
else
sprintf(bufr, "*i18nDlg.ismapped: False\n");
WRITE_STR2FD(fd, bufr);
/* Get and write out the geometry info for our Window */
x = XtX(XtParent(style.i18nDialog));
y = XtY(XtParent(style.i18nDialog));
@@ -1204,13 +1206,14 @@ saveI18n(
width = XtWidth(style.i18nDialog);
height = XtHeight(style.i18nDialog);
snprintf(bufr, sizeof(style.tmpBigStr), "%s*i18nDlg.x: %d\n", bufr, x);
snprintf(bufr, sizeof(style.tmpBigStr), "%s*i18nDlg.y: %d\n", bufr, y);
snprintf(bufr, sizeof(style.tmpBigStr), "%s*i18nDlg.width: %d\n", bufr, width);
snprintf(bufr, sizeof(style.tmpBigStr), "%s*i18nDlg.height: %d\n", bufr, height);
if(-1 == write (fd, bufr, strlen(bufr))) {
perror(strerror(errno));
}
snprintf(bufr, sizeof(bufr), "*i18nDlg.x: %d\n", x);
WRITE_STR2FD(fd, bufr);
snprintf(bufr, sizeof(bufr), "*i18nDlg.y: %d\n", y);
WRITE_STR2FD(fd, bufr);
snprintf(bufr, sizeof(bufr), "*i18nDlg.width: %d\n", width);
WRITE_STR2FD(fd, bufr);
snprintf(bufr, sizeof(bufr), "*i18nDlg.height: %d\n", height);
WRITE_STR2FD(fd, bufr);
}
}