For a while, I had trouble reproducing this depending on which
libraries were loaded. But you can do it pretty consistently by adding
this just above the quoted code block:
memset(data.wid.cStreamName, 1, _MAX_PATH * sizeof(wchar_t));
I do have a standalone, un-emacs-ified copy of this function too (the
exact same code as wmain) if anyone else wants to test.
Stephen J. Turnbull wrote:
Reply-To set to xemacs-patches; please check that your MUA DTRTs.
Ron, do you have a test case? I guess that would be hard given that
you need to control layout of memory, but maybe if you do it in a loop
you get it fairly frequently?
Reviewers: could somebody confirm the problem and that the patch works
as expected? (I can't test, I'm Windows-free at the moment.) I trust
Ron and the theory, so if no test, I'll commit in a couple of days.
Please check the ChangeLog in the patch.
Ron Isaacson writes:
> Not sure if anyone is using (add-name-to-file) on Windows, as this bug
> looks to have been here for a while... the mswindows_link function in
> nt.c does:
> wcscpy (data.wid.cStreamName, newuni);
> data.wid.dwStreamId = BACKUP_LINK;
> data.wid.dwStreamAttributes = 0;
> data.wid.Size.LowPart = wlen; /* in bytes, not chars! */
> data.wid.Size.HighPart = 0;
> data.wid.dwStreamNameSize = 0;
> The comment about bytes is correct, but is missing one important
> detail: wlen contains wcslen(newuni), but BackupWrite expects the Size
> to include the trailing null. So depending on what happens to follow
> in memory, the new file might have a garbage name.
> When I started seeing these garbage filenames, I copied mswindows_link
> out to a standalone program and was able to consistently reproduce the
> This is fixed by changing it to:
> data.wid.Size.LowPart = wlen + sizeof(WCHAR); /* including the trailing
null. in bytes, not chars! */
diff -r 00dca3ddee6d src/ChangeLog
--- a/src/ChangeLog Mon May 18 23:04:48 2009 +0900
+++ b/src/ChangeLog Tue Jun 02 12:16:27 2009 +0900
＠＠ -1,3 +1,8 ＠＠
+2009-06-02 Ron Isaacson <Ron.Isaacson(a)morganstanley.com>
+ * nt.c (mswindows_link): Fix off-by-one bug in mswindows_link:
+ need to include trailing NUL in length of file name.
2009-05-18 Stephen J. Turnbull <stephen(a)xemacs.org>
* XEmacs 21.5.29 "garbanzo" is released.
diff -r 00dca3ddee6d src/nt.c
--- a/src/nt.c Mon May 18 23:04:48 2009 +0900
+++ b/src/nt.c Tue Jun 02 12:16:27 2009 +0900
＠＠ -1127,7 +1127,8 ＠＠
wcscpy (data.wid.cStreamName, newuni);
data.wid.dwStreamId = BACKUP_LINK;
data.wid.dwStreamAttributes = 0;
- data.wid.Size.LowPart = wlen; /* in bytes, not chars! */
+ /* Include the trailing null. In bytes, not chars! */
+ data.wid.Size.LowPart = wlen + sizeof (WCHAR);
data.wid.Size.HighPart = 0;
data.wid.dwStreamNameSize = 0;
ron.isaacson(a)morganstanley.com / (212) 762-1051
XEmacs-Patches mailing list