Closed Bug 135292 Opened 22 years ago Closed 22 years ago

unsigned int being compared to -1

Categories

(Core Graveyard :: Plug-ins, defect, P3)

defect

Tracking

(Not tracked)

VERIFIED FIXED
mozilla1.2beta

People

(Reporter: anthonyd, Assigned: anthonyd)

Details

(Whiteboard: [PL2:NA][patch])

Attachments

(1 file, 4 obsolete files)

actual code in question:
ns4xPluginInstance.cpp, line 252
  if (mNPStream.end == -1)
    mNPStream.end = 0;

getting set to -1 in nsPluginHostImpl.cpp, line 2103.

Fix or not? seems like we should, but I'm cold and scared.

anthonyd
Attached patch patch to fix the bug (obsolete) — Splinter Review
Tony, did you check the test cases from bug 52963, bug 52965 ?
it's about java servlet connectivity through nsIPluginManager::GetURL/PostURL
are there any reasons for that code?
+  // it's possible for the server to not send a Content-Length.  We should
+  // still work in this case.
+  if (NS_FAILED(rv)) {
+    mPluginStreamInfo->SetLength(-1);

BTW: is there a posibility to get -1 from channel ?
  rv = channel->GetContentLength(&length);
  // it's possible for the server to not send a Content-Length.  We should
  // still work in this case.
  if (NS_FAILED(rv)) {
    mPluginStreamInfo->SetLength(-1);
  }
  else {
    mPluginStreamInfo->SetLength(length);
  }
Its not so much about whether there is a reason for the code as it is about
whether the code is correct. In the patch I attached, mNPStream.end (which is an
unsigned int32) get assinged a -1 with the following block:

nsPluginHostImpl.cpp
    mPluginStreamInfo->SetLength(-1);

at some point later in the code, it is compared to -1 and set to zero if true:

ns4xPluginInstance.cpp
  if (mNPStream.end == -1)
    mNPStream.end = 0;

That variable is only set to -1 (really just FFFFF....) in one place, so after
talking with peterl, the safe thing seemed to be to just go ahead and assign it
to zero, since that seemed to be the purpose anyway of the code.

It appeared to be just blind luck that the code was working in the first place,
if that had been an unsigned short for instance, it would have failed.

As to the testcases you mention, I will rebuild and test them, but peterl would
be a better choice to ask about further ramifications of this small change.

anthonyd
I'm just worried that someone may be expecting this -1 (FFFFFF) behavior.
patch attached.
Whiteboard: [patch]
1.2beta
Priority: -- → P3
Target Milestone: --- → mozilla1.2beta
Whiteboard: [patch] → [PL2:NA][patch]
adding nsbeta1+ for buffy
Status: NEW → ASSIGNED
Keywords: nsbeta1+
need r's and sr's for this patch.
Whiteboard: [PL2:NA][patch] → [PL2:NA][patch][need r=, sr=]
Comment on attachment 78462 [details] [diff] [review]
patch to fix the bug

The code seems to be logically equivalent to what it was. r=av. Maybe it would
be nicer to write it in one line:

mPluginStreamInfo->SetLength(NS_SUCCEEDED(rv) ? length : 0);

and make sure that testcases from all related bugs still work.
Attachment #78462 - Flags: review+
Comment on attachment 78462 [details] [diff] [review]
patch to fix the bug

Serge just pointed out... We probably don't want commented out source lines
dangling in the code, please make sure you remove them before you check in. Or
better, attach a new patch.
Attached patch alt patch (obsolete) — Splinter Review
I wouldn't remove this due to next comment
   // if we don't know the end of the stream, use 0 instead of -1. bug 59571
-  if (mNPStream.end == -1)
+  if ((int)mNPStream.end == -1)
Comment on attachment 94718 [details] [diff] [review]
alt patch

Serge, but in the original patch, we already set it to null if we don't know
the length.
Attached patch alt v2 (obsolete) — Splinter Review
all right after conversation with av we decided it safe now to remove 
if (mNPStream.end == -1)
from ns4xPluginStreamListener::OnStartBinding
Attachment #94718 - Attachment is obsolete: true
oops, wrong attachment:(
Attached patch alt v3 (obsolete) — Splinter Review
it's a right one now
Attachment #94722 - Attachment is obsolete: true
Comment on attachment 94724 [details] [diff] [review]
alt v3

r=av
Attachment #94724 - Flags: review+
I don't have a problem with the new patch, but who do I get a sr from?
Whiteboard: [PL2:NA][patch][need r=, sr=] → [PL2:NA][patch][need sr]
Comment on attachment 94724 [details] [diff] [review]
alt v3

>Index: nsPluginHostImpl.cpp

>+  PRInt32 length = 0;
>+  channel->GetContentLength(&length);
>+  mPluginStreamInfo->SetLength(length);

you must check the return value of GetContentLength.  it might fail,
and upon failing it might set length to some arbitrary value that
isn't at all consistent with the concept of content length.
Attachment #94724 - Flags: needs-work+
well, I thought idl out param suppose to be unattached or set to 0 on failure.
but it looks like there is no such requirements for out params:(
lets use av's patch from comment #10
PRInt32 length;
rv = channel->GetContentLength(&length)
mPluginStreamInfo->SetLength(NS_SUCCEEDED(rv) ? length : 0);
Though it probably doesn't matter for this particular case, I really don't like
the trinary argument because it is harder to debug (putting breakpoints).  There
is also no real point because any decent compiler will make sure that a trinary
is equivalent to a if/else block.

Anyway, whichever patch you want, just let me know.

ADavis
please attach the patch you like.
I think the original patch was the simplest and most straight forward (other
than the commented out lines of code, which I should have just deleted).

I will go ahead and reattach the patch WITHOUT the commented out lines of code.
 But is there a technical error with the original patch?

Thanks,
ADavis
Comment on attachment 78462 [details] [diff] [review]
patch to fix the bug

the patch looks good, except the comments
>+  //if (mNPStream.end == -1)
>+  //  mNPStream.end = 0; // see bug # 135292
>...
>+//    mPluginStreamInfo->SetLength(-1);
>+    mPluginStreamInfo->SetLength(0);// see bug # 135292
Attachment #78462 - Flags: needs-work+
this is the simple patch with the comments removed.  just need the r= and sr=
to get this finsihed.

thanks all.
Attachment #78462 - Attachment is obsolete: true
Attachment #94724 - Attachment is obsolete: true
Comment on attachment 95470 [details]
new version of original patch

r=serge
Attachment #95470 - Flags: review+
Comment on attachment 95470 [details]
new version of original patch

sr=darin
Attachment #95470 - Flags: superreview+
got everything I need, will check in ASAP.

thanks everyone.
anthonyd
Whiteboard: [PL2:NA][patch][need sr] → [PL2:NA][patch]
checked in to trunk.
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
.
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: