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

@@ -1750,17 +1750,19 @@ saveMouse(
int fd )
{
Position x,y;
char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
char bufr[1024]; /* size=[1024], make bigger if needed */
XmVendorShellExtObject vendorExt;
XmWidgetExtData extData;
if (style.mouseDialog != NULL)
if (style.mouseDialog != NULL)
{
if (XtIsManaged(style.mouseDialog))
sprintf(bufr, "*Mouse.ismapped: True\n");
else
sprintf(bufr, "*Mouse.ismapped: False\n");
WRITE_STR2FD(fd, bufr);
/* Get and write out the geometry info for our Window */
x = XtX(XtParent(style.mouseDialog));
y = XtY(XtParent(style.mouseDialog));
@@ -1773,12 +1775,10 @@ saveMouse(
x -= vendorExt->vendor.xOffset;
y -= vendorExt->vendor.yOffset;
snprintf(bufr, sizeof(style.tmpBigStr), "%s*Mouse.x: %d\n", bufr, x);
snprintf(bufr, sizeof(style.tmpBigStr), "%s*Mouse.y: %d\n", bufr, y);
if(-1 == write (fd, bufr, strlen(bufr))) {
perror(strerror(errno));
}
snprintf(bufr, sizeof(bufr), "*Mouse.x: %d\n", x);
WRITE_STR2FD(fd, bufr);
snprintf(bufr, sizeof(bufr), "*Mouse.y: %d\n", y);
WRITE_STR2FD(fd, bufr);
}
}