Closed
Bug 423401
Opened 18 years ago
Closed 15 years ago
Please use a local variable and copy the string once
Categories
(Core :: Security: PSM, defect)
Tracking
()
RESOLVED
FIXED
mozilla2.0b8
People
(Reporter: timeless, Assigned: ewong)
References
()
Details
(Whiteboard: [psm-logic][psm-easy])
Attachments
(1 file, 3 obsolete files)
|
949 bytes,
patch
|
ewong
:
review+
benjamin
:
approval2.0+
|
Details | Diff | Splinter Review |
the current code does pointer work on a string which should be local until it's done.
it's also doing Append the first time instead of some flavor of Assign. nsPrintfCString might be useful...
Comment 1•15 years ago
|
||
This bug report currently depends on cvs-blame to work.
I'm pasting the relevant information, so we know which code this refers to:
in SECStatus nsNSSHttpRequestSession::createFcn
rs->mURL.Append(nsDependentCString(http_protocol_variant));
rs->mURL.AppendLiteral("://");
rs->mURL.Append(hss->mHost);
rs->mURL.AppendLiteral(":");
rs->mURL.AppendInt(hss->mPort);
rs->mURL.Append(path_and_query_string);
Updated•15 years ago
|
Assignee: kaie → nobody
Whiteboard: [psm-logic]
Updated•15 years ago
|
Whiteboard: [psm-logic] → [psm-logic][psm-easy]
| Assignee | ||
Updated•15 years ago
|
Assignee: nobody → ewong
Status: NEW → ASSIGNED
| Assignee | ||
Comment 2•15 years ago
|
||
Attachment #459736 -
Flags: review?
| Assignee | ||
Updated•15 years ago
|
Attachment #459736 -
Flags: review? → review?(kaie)
| Assignee | ||
Comment 3•15 years ago
|
||
Cleaned the code as suggested by timeless via IRC.
Attachment #459736 -
Attachment is obsolete: true
Attachment #459738 -
Flags: review?
Attachment #459736 -
Flags: review?(kaie)
| Assignee | ||
Updated•15 years ago
|
Attachment #459738 -
Flags: review? → review?(kaie)
Comment 4•15 years ago
|
||
Comment on attachment 459736 [details] [diff] [review]
Used a local variable to gather the information and then it is assigned to the url.
>+ int slen = 16 + strlen(http_protocol_variant) +
>+ nsPromiseFlatCString(hss->mHost).Length()+
>+ strlen(path_and_query_string);
Any reason not to use strlen on hss->mHost?
>+ nsPromiseFlatCString(hss->mHost).get(),
This is almost the same as hss->mHost, but much more work.
Also you're not supposed to use nsPromiseFlatCString directly.
| Assignee | ||
Comment 5•15 years ago
|
||
(In reply to comment #4)
> Comment on attachment 459736 [details] [diff] [review]
> Used a local variable to gather the information and then it is assigned to the
> url.
>
> >+ int slen = 16 + strlen(http_protocol_variant) +
> >+ nsPromiseFlatCString(hss->mHost).Length()+
> >+ strlen(path_and_query_string);
> Any reason not to use strlen on hss->mHost?
>
I had an issue with doing strlen(hss->mHost). Gave me the
following error:
nsNSSCallbacks.cpp(241) : error C2664: 'strlen' : cannot convert parameter 1 from 'nsCString' to 'const char *'
> >+ nsPromiseFlatCString(hss->mHost).get(),
> This is almost the same as hss->mHost, but much more work.
>
> Also you're not supposed to use nsPromiseFlatCString directly.
Is the second patch better? It doesn't call nsPromiseFlatCString
directly.
Comment 6•15 years ago
|
||
I don't understand why there is a need to change the nice and safe object oriented string approach to an old-world C-style approach, that requires the introduction of arbitrary numbers like "16" into the code, which readers will have trouble to understand. Why 16?
From the comment of nsPrintfCString:
"If your formatted string exceeds the allocated space, it is cut off at the size of the buffer, no error is reported"
Yes, it's probably unlikely that in the future the port number will be a 64 bit number that has a very long result and will be longer than 12 chars, but who knows?
I'm not in favour of changing code that currently deals correctly with any length of numbers into code that behaves wrong for some numbers.
I have trouble to understand the motivation for this bug report.
The initial comment should have been written more clearly.
What exactly do you mean with "pointer work on a string which should be local until it's done." and to which of the lines are you referring to?
Please clarify that.
Is is that you're worried about the combination of "Append" with "nsDependentCString" in a single statement, which might introduce a pointer to a temporary object? If you want to clear that up, fair enough, but there is no need to rewrite the whole code simply for this fix. Simply move the nsDependentCString definition to an earlier separate line, so it's no longer a temporary.
On the other hand, if you look at the code, both http_protocol_variant and path_and_query_string and simply "const char *". It seems inconsistent why the current code uses different treatment (once a direct append, once an append using the nsDep...).
I propose to use the same style for both. It looks like nsDep. can be avoided at all, so the above split is not even necessary (simply remove nsDep.)
If you're worried about the lack of initial assignment, well, I personally thing it's not a big deal. Most likely the construction of an empty string object won't involve a memory allocation at all, so I don't see an advantage of changing it to use an initial assignment.
If you're really that worried about multiple allocations, then you can use rs->mURL.SetCapacity(expected-maximum-value).
| Assignee | ||
Comment 7•15 years ago
|
||
Attachment #459738 -
Attachment is obsolete: true
Attachment #461129 -
Flags: review?
Attachment #459738 -
Flags: review?(kaie)
| Assignee | ||
Updated•15 years ago
|
Attachment #461129 -
Flags: review? → review?(kaie)
Comment 8•15 years ago
|
||
Comment on attachment 461129 [details] [diff] [review]
Removed nsDependentCString() usage.
r=kaie
Attachment #461129 -
Flags: review?(kaie) → review+
| Assignee | ||
Updated•15 years ago
|
Attachment #461129 -
Flags: review?(honzab.moz)
Updated•15 years ago
|
Attachment #461129 -
Flags: review?(honzab.moz) → review+
| Assignee | ||
Comment 9•15 years ago
|
||
Changed patch to be more checkin-needed friendly.
Bug 423401 - Removed nsDependentCString() usage. r=kaie, r=honzab.moz
Attachment #461129 -
Attachment is obsolete: true
Attachment #471498 -
Flags: review+
| Assignee | ||
Updated•15 years ago
|
Keywords: checkin-needed
| Assignee | ||
Updated•15 years ago
|
Attachment #471498 -
Flags: approval2.0?
Updated•15 years ago
|
Attachment #471498 -
Flags: approval2.0? → approval2.0+
Comment 10•15 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b8
You need to log in
before you can comment on or make changes to this bug.
Description
•