Closed
Bug 278306
Opened 20 years ago
Closed 20 years ago
Possible unexpected truncation of path in GRE_GetCurrentProcessDirectory
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: Callek, Assigned: Callek)
References
()
Details
Attachments
(2 files)
|
1.56 KB,
patch
|
darin.moz
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
|
1.04 KB,
patch
|
dougt
:
review+
|
Details | Diff | Splinter Review |
DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename, DWORD nSize);
Return Values
If the function succeeds, the return value is the length of the string copied to
the buffer, in TCHARs. If the buffer is too small to hold the module name, the
string is truncated to nSize, and the function returns nSize.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
If the return value is > MAXPATHLEN here we should return PR_FALSE, better than
what we have now.
Patch Coming...
| Assignee | ||
Comment 1•20 years ago
|
||
This should fix it.
Assignee: dougt → 116057
Status: NEW → ASSIGNED
Attachment #171202 -
Flags: superreview?(darin)
Attachment #171202 -
Flags: review?(darin)
Comment 2•20 years ago
|
||
Comment on attachment 171202 [details] [diff] [review]
fix
The documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/g
etmodulefilename.asp
Does not talk about a return value greater than MAXPATHLEN. Why would be test
for it? I would claim that GetModuleFileName would be broken if the return
value is greater than nSize. Where do you see this happening?
Attachment #171202 -
Flags: superreview?(darin)
Attachment #171202 -
Flags: review?(darin)
Attachment #171202 -
Flags: review-
Comment 3•20 years ago
|
||
Comment on attachment 171202 [details] [diff] [review]
fix
>Index: xpcom/glue/standalone/nsGREDirServiceProvider.cpp
>+ DWORD bufLength = ::GetModuleFileName(0, buffer, MAXPATHLEN);
>+ if (bufLength == 0 || bufLength >= MAXPATHLEN)
>+ return PR_FALSE;
>+ // chop of the executable name by finding the rightmost backslash
>+ char* lastSlash = PL_strrchr(buffer, '\\');
BTW, this should probably use _mbsrchr instead of PL_strrchr though
in practice I don't know of any character encodings where the current
code would be a problem (but in nsLocalFileWin.cpp we use _mbsrchr
when searching for '\\' so maybe there is a reason).
r+sr=darin with that change.
Attachment #171202 -
Flags: superreview+
Attachment #171202 -
Flags: review-
Attachment #171202 -
Flags: review+
Comment 4•20 years ago
|
||
fixed-on-trunk
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Comment 5•20 years ago
|
||
> Does not talk about a return value greater than MAXPATHLEN. Why would be test
> for it? I would claim that GetModuleFileName would be broken if the return
> value is greater than nSize. Where do you see this happening?
MSDN says: "If the buffer is too small to hold the module name, the string is
truncated to nSize, and the function returns nSize." In this case MAXPATHLEN is
that nSize. Given this documentation, it would have probably been fine to
compare using == instead of >=.
Sorry for not responding to your comment before checking in. I didn't see it
when I first visited the bug. Comments posted from the edit patch feature don't
handle conflict resolution IIRC :-(
| Assignee | ||
Comment 6•20 years ago
|
||
This fixes the >= to ==, for some reason I thought I read something like
"returns the size needed for the buffer" or some such, which of course would be
nicer since other app's could then allocate what is needed, O well. Thanks
Attachment #171225 -
Flags: superreview?(dougt)
Attachment #171225 -
Flags: review?(dougt)
Comment 7•20 years ago
|
||
Comment on attachment 171225 [details] [diff] [review]
Address Doug's Review comment
yeah, that works.
Attachment #171225 -
Flags: review?(dougt) → review+
Updated•20 years ago
|
Attachment #171225 -
Flags: superreview?(dougt)
You need to log in
before you can comment on or make changes to this bug.
Description
•