Closed
Bug 161634
Opened 22 years ago
Closed 22 years ago
[ps] envvar should not be freed after PR_SetEnv
Categories
(Core :: Printing: Output, defect)
Tracking
()
RESOLVED
FIXED
mozilla1.2alpha
People
(Reporter: ajschult784, Assigned: roland.mainz)
References
Details
(Keywords: fixedOEM)
Attachments
(3 files, 2 obsolete files)
2.07 KB,
patch
|
dcone
:
review+
|
Details | Diff | Splinter Review |
2.31 KB,
patch
|
bzbarsky
:
superreview+
|
Details | Diff | Splinter Review |
2.32 KB,
patch
|
jesup
:
review+
jesup
:
superreview+
jesup
:
approval+
|
Details | Diff | Splinter Review |
this is a regression from bug 84947
http://lxr.mozilla.org/mozilla/source/gfx/src/ps/nsPostScriptObj.cpp#381
381 PR_SetEnv(envvar);
382 free(envvar);
this is bad. Linux seems to copy by reference instead of copying the data.
From prenv.h:
** The caller must ensure that the string passed
** to PR_SetEnv() is persistent. That is: The string should
** not be on the stack, where it can be overwritten
** on return from the function calling PR_SetEnv().
** Similarly, the string passed to PR_SetEnv() must not be
** overwritten by other actions of the process. ... Some
** platforms use the string by reference rather than copying
** it into the environment space. ... You have been warned!
Comment 1•22 years ago
|
||
I'd say this is more like critical... this is a crash or security problem
waiting to happen.
Severity: normal → critical
PR_SetEnv is sitting on top of putenv on unix and the putenv semantics
require that a name=value string be used as is. The address is put into
the new environment but the string itself is *not* copied. It's used as
is. A wonderful way to leak memory and cause crashes.
Maybe this is actually a nspr bug, nsprpub/pr/include/prenv.h says
NSPR_API(PRStatus) PR_SetEnv(const char *string);
but, if you build mozilla with enough warnings turned on, you'll get a
message about the function discarding 'const'. A big hint if anyone ever
looks at warnings.
Assignee | ||
Comment 3•22 years ago
|
||
Nice catch... :)
... accepting bug.
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla1.2alpha
Assignee | ||
Comment 4•22 years ago
|
||
*** Bug 143480 has been marked as a duplicate of this bug. ***
Assignee | ||
Updated•22 years ago
|
Summary: envvar should not be freed after PR_SetEnv → [ps] envvar should not be freed after PR_SetEnv
Assignee | ||
Comment 5•22 years ago
|
||
*** Bug 136146 has been marked as a duplicate of this bug. ***
Assignee | ||
Comment 6•22 years ago
|
||
I replaced the dynamically allocated buffer with a |static| buffer - this
should be sufficient to fix the problem.
Assignee | ||
Updated•22 years ago
|
Assignee | ||
Comment 7•22 years ago
|
||
The first patch does only work the first time we print, any following print
session doesn't work since we're writing to memory which is still linked to the
env var pool... - this new patch should fix that (in theory) ...
Attachment #94581 -
Attachment is obsolete: true
Comment 8•22 years ago
|
||
dcone, syd
can you r=
Comment 9•22 years ago
|
||
Comment on attachment 94588 [details] [diff] [review]
New patch for 2002-08-04-08-trunk
r=dcone
Attachment #94588 -
Flags: review+
Comment 10•22 years ago
|
||
Comment on attachment 94588 [details] [diff] [review]
New patch for 2002-08-04-08-trunk
>+ PR_SetEnv("MOZ_PRINTER_NAME=dummy_value_to_make_putenv_happy");
>+
> sprintf(envvar, "MOZ_PRINTER_NAME=%s", printername);
That needs to become an snprintf so we don't write outside our buffer, no?
Attachment #94588 -
Flags: needs-work+
Comment 11•22 years ago
|
||
using snprintf instead sprintf for safty
Comment 12•22 years ago
|
||
Attachment #95345 -
Attachment is obsolete: true
Comment 13•22 years ago
|
||
Comment on attachment 95354 [details] [diff] [review]
same as previous one, using diff -u
> nchars > ARG_MAX
that should be '>=', not '>' (since if your string is ARG_MAX chars it will get
truncated by one char and ARG_MAX will be the return value with recent libc
versions).
sr=bzbarsky with that change.
Attachment #95354 -
Flags: superreview+
Comment 14•22 years ago
|
||
actaully, as Louie just noticed, that should not be "return sprintf". And the
temporary should be PRInt32, not "int".
Comment 15•22 years ago
|
||
Comment 16•22 years ago
|
||
checked in trunk
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Updated•22 years ago
|
Whiteboard: branchOEM
Comment 17•22 years ago
|
||
checked in NETSCAPE_7_0_OEM_BRANCH (a=jdunn)
Whiteboard: branchOEM+ → branchOEM+ fixedOEM
Assignee | ||
Comment 18•22 years ago
|
||
*** Bug 134914 has been marked as a duplicate of this bug. ***
Comment 20•22 years ago
|
||
Comment on attachment 95361 [details] [diff] [review]
final patch(r=dcone, sr=bzbarsky)
Marking the r/sr.
a=rjesup@wgate.com for 1.0 branch. you know the drill
Attachment #95361 -
Flags: superreview+
Attachment #95361 -
Flags: review+
Attachment #95361 -
Flags: approval+
Updated•22 years ago
|
Keywords: mozilla1.0.2 → mozilla1.0.2+
Assignee | ||
Comment 21•22 years ago
|
||
*** Bug 172726 has been marked as a duplicate of this bug. ***
You need to log in
before you can comment on or make changes to this bug.
Description
•