Bad string handling in PRINTDLG_UpdatePrintDlg?

Francois Gouget fgouget at free.fr
Sat Apr 24 18:36:53 CDT 2004


In PRINTDLG_UpdatePrintDlgA() in dlls/commdlg/printdlg.c we do:

...
    LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
...
	    pi->pPortName = "FILE:";

And in PRINTDLG_UpdatePrintDlgW() we do:

...
    LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
...
	    static WCHAR file[] = {'F','I','L','E',':',0};
	    pi->pPortName = file;
...


Now in gcc all string literals are read-only, even if you declare them
as char* foo="bar", *foo='\0' will cause a segfault.

So in the Ansi version we point pPortName to a read-only string. But if
the application gets hold of that pointer we have no garantee that it
won't expect to be able to modify that string: pPortName is an LPSTR.
(this is a case where -Wwrite-strings will complain)

And in the Unicode case we point pPortName to a static writable buffer.
But in this case if the application writes in our buffer its contents is
going to be messed up forever.

However I don't know this code at all. So I'm asking, shoudln't we make
a copy of these strings? Which also raises the ugly issue of later
freeing the corresponding memory buffer...


-- 
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
  Any sufficiently advanced Operating System is indistinguishable from Linux



More information about the wine-devel mailing list