Some HRESULT values not equal in COM and JScript 
Author Message
 Some HRESULT values not equal in COM and JScript

Hi there

This is propably a trivial question, but after 3 hours searching the
MSDN and groups.google.com, I have given up, and are now ready for
asking the masters ;-)

I am writing a com-component that should be called from JScript, and
when I return a failed HRESULT there of course gets thrown an
Error-object in the JScript code. But if I check the number-property of
that error they are not always equal to the values in the
Winerror.h-file. Example:

In my C-code I return the following
        return E_ACCESSDENIED; // is 0x80070005 according to winerror.h

but in my JScript code:
        try {
                myActiveXComp.someMethod(); // returns the above hresult
        } catch (e) {
                var mostSign = ((e.number >> 16) & 0xFFFF).toString(16);
                var leastSign = (e.number & 0x0000FFFF).toString(16);
                alert(mostSign + ":" + leastSign);
        }

The alert-dialog gives: "800a:46" and I would have expected it to give
something like: "8007:5". (I make the separation into mostSign and
leastSign, because just doing "alert(e.number.toString(16))" would give
me "-7ff5ffba").

But if I instead returns E_FAIL (should be 0x80004005), I do get the
expected value "8000:4005" on the JScript side.

Have I overlooked something, or am I doing something wrong?

Best Regards and thanks in advance for any help
Morten Andersen



Thu, 08 Jul 2004 04:05:45 GMT  
 Some HRESULT values not equal in COM and JScript

Quote:

> Hey Morten,

> JScript hides the "Access denied" message because it is a potential security
> problem. "How can it be a security problem to say Access Denied?", you ask.
> Well, there is a common principal in security that says you never give
> someone more information than they need; otherwise you could leak stuff you
> didn't mean to.

[SNIP - Path discovery example]

Quote:
> Because of things like this, the script engines translate "Access Denied"
> into something like "The operation failed" so that we don't give out too
> much information.

> Peter

Hi Peter and thanks for answering

I do understand the implication of giving to detailed
error-informations, to a potentionally malicius user of ones
application. But with all respect for your answer, I am not certain that
this argument holds in this case, since the description-property of the
thrown Error-object is the expected string (which in the E_ACCESSDENIED
case means: "Permission denied").

And the HRESULT value it is mapped to does not seem to be some general
value that hides all security-sensitive HRESULT's because for example
the E_INVALIDARG (0x80000003) is mapped to 0x800A0005 (remember the
E_ACCESSDENIED was mapped to 0x800A0046).

And if the HRESULTS really are changed due to security, shouldn't it be
documented somewhere (which is propably is, I just haven't found it yet
;-)), that the script-engine maps the HRESULTS in a certain range to a
specific general exception.

Best regards
Morten Andersen

Quote:

> --

> Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
> Please post all questions to the group. Thanks.



Thu, 08 Jul 2004 17:11:59 GMT  
 Some HRESULT values not equal in COM and JScript
"Morten Andersen"

message

...

Quote:
> I do understand the implication of giving to detailed
> error-informations, to a potentionally malicius user of ones
> application. But with all respect for your answer, I am not certain that
> this argument holds in this case, since the description-property of the
> thrown Error-object is the expected string (which in the E_ACCESSDENIED
> case means: "Permission denied").

> And the HRESULT value it is mapped to does not seem to be some general
> value that hides all security-sensitive HRESULT's because for example
> the E_INVALIDARG (0x80000003) is mapped to 0x800A0005 (remember the
> E_ACCESSDENIED was mapped to 0x800A0046).

OK, I looked into it a bit further and now it makes sense. Should have
thought just a little bit harder before opening my mouth ;-)

We remap that specific error because the script engines have their own
"Permission Denied" error (if you look at the resources for JScript.dll or
VBScript.dll you will see that resource string 70 (0x46) is "Permission
Denied". This is probably a historical issue dating back to Visual Basic and
VBScript wanting to keep VB's old internal error numbers. So it appears that
we map Windows' "Access Denied" to VB's "Permission Denied". That explains
the remapping.

As for the security aspect, YOU should be the one doing the remapping if
your component is supposed to be safe (is marked as "Safe for Scripting").
If your component is not safe for scripting then it is fine for you to say
"Access Denied" and for us to propagate that information to the user. If
your component is marked as "Safe for Scripting" then you should not be
propogating that error.

We *do* remap some errors when you call "new ActiveXObject()" because
otherwise the script engine would be leaking information. I just assumed
that we were doing the same here, but we are not and thanks to your
persistence we've both learned something ;-). The logic goes like this:

JScript tries to create the object. If we are in a restricted environment
(eg, Internet Explorer) then if your component is not safe it won't get
created. If your component is safe then we will let it run. We remap the
specific errors that have built-in equivalents (as noted above), but don't
do any other security filtering (after all, you claimed to be safe, and we
assume you know what you are doing).

If we are not in a restricted environment (eg, WSH) then who cares? We
create your object and propagate all errors.

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.



Fri, 09 Jul 2004 05:59:26 GMT  
 Some HRESULT values not equal in COM and JScript
Hi Peter

Great, thanks for spending time on this! This one I believes ;-). And
just as long as the remapping happens to the FACILITY_CONTROL (the A in
0x800A0046) area, I can be sure that it won't interfere with my
component-specific HRESULTS.

And for your statement about, that the ActiveX-writer should be
responsible for hiding security-vulnerable HRESULT's, I totally agree.
After all he/she is the one with the knowledge of the specific area that
the component is in.

Best Regards
Morten Andersen

Quote:

> ------------------------------------------------------------------------

[SNIP]


Fri, 09 Jul 2004 07:02:45 GMT  
 Some HRESULT values not equal in COM and JScript
"Morten Andersen"

message

...

Quote:
> Hi Peter

> Great, thanks for spending time on this! This one I believes ;-).

Hehehe. Free unsupported advice given by a Program Manager on a Saturday
afternoon should always be taken with a large grain of salt ;-)

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.



Fri, 09 Jul 2004 07:38:54 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Capturing return values in JScript from C++ COM objects

2. Check Box being checked if database value is equal to ON

3. how to handle com events within a jscript but not a wscript environment

4. HTML source file is not the same on equal browsers

5. Help: eps not all equal?

6. Problem for MSIE DOM experts: document methodes: this not equal document

7. .vbs file to play a .wav if file size does not equal 0

8. enumerating values in a control (works in VBScript, not in JScript)

9. Why does VB COM not return values when using Jscript ASP instead of VBscript?

10. integer arithmetics and HRESULT

11. Can you get to the HRESULT?

 

 
Powered by phpBB® Forum Software