Valerie:

Thanks for catching this inconsistency. I just posted a modified webrev image:
http://cr.openjdk.java.net/~jzavgren/8007607/webrev.08/

John


<br>----- Original Message -----<br>From: valerie.p...@oracle.com<br>To: 
john.zavg...@oracle.com<br>Cc: security-dev@openjdk.java.net<br>Sent: 
Wednesday, March 13, 2013 9:07:45 PM GMT -05:00 US/Canada Eastern<br>Subject: 
Re: RFR: JDK-8007607<br><br><html>
  <head>
    
  </head>
  <div>
    <br>
    Looks fine, just a very minor nit.<br>
    &lt;GSSLibStub.c&gt;<br>
    - line 544: although the return value isn&#39;t really used, maybe you
    should return <span class="changed">jlong_zero instead of -1 for
      consistency sake.</span><br>
    <br>
    Thanks,<br>
    Valerie<br>
    On 03/12/13 08:34, John Zavgren wrote:
    <blockquote cite="mid:513f4ae8.7080...@oracle.com">
      
      <div class="moz-cite-prefix">Greetings:<br>
        I&nbsp; posted a new webrev image in response to the most recent
        round of comments:<br>
        
        <a href="http://cr.openjdk.java.net/%7Ejzavgren/8007607/webrev.07/"; 
target="_blank">http://cr.openjdk.java.net/~jzavgren/8007607/webrev.07/</a><br>
        <br>
        Thanks!<br>
        John<br>
        <br>
        On 02/19/2013 12:16 PM, Chris Hegarty wrote:<br>
      </div>
      <blockquote cite="mid:5123b35c.6080...@oracle.com">Hi
        John, <br>
        <br>
        Functionally this looks fine. Most my comments are nit picking,
        and style. <br>
        <br>
        src/share/native/sun/security/jgss/wrapper/GSSLibStub.c <br>
        <br>
        &nbsp; My fault, I think I suggested you return NULL, but since these
        <br>
        &nbsp; methods return jlong they cannot (without generating
        warnings). <br>
        &nbsp; It would be better to: <br>
        <br>
        &nbsp;&nbsp; &lt; 332&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return NULL; <br>
        &nbsp;&nbsp; --- <br>
        &nbsp;&nbsp; &gt; 332&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return jlong_zero; <br>
        <br>
        &nbsp;&nbsp; 1167&nbsp;&nbsp;&nbsp;&nbsp; return NULL;&nbsp; [same 
comment, return jlong_zero] <br>
        <br>
        &nbsp; The indentation looks a little too much in a few places, e.g.
        <br>
        &nbsp;&nbsp;&nbsp; 331&nbsp;&nbsp; if ((*env)-&gt;ExceptionCheck(env)) 
{ <br>
        &nbsp;&nbsp;&nbsp; 332&nbsp;&nbsp; ______return NULL; <br>
        &nbsp;&nbsp;&nbsp; 333&nbsp;&nbsp; } <br>
        <br>
        <br>
        src/share/native/sun/security/jgss/wrapper/NativeUtil.c <br>
        <br>
        &nbsp; 620&nbsp;&nbsp;&nbsp;&nbsp; cOid = malloc(sizeof(struct 
gss_OID_desc_struct)); <br>
        &nbsp; 621&nbsp;&nbsp;&nbsp;&nbsp; if_(cOid == NULL) {&nbsp;&nbsp; [add 
a space after if] <br>
        &nbsp; 622&nbsp;&nbsp;&nbsp;&nbsp; 
____throwOutOfMemoryError(env,NULL);&nbsp; [I would suggest
        2 spaces] <br>
        &nbsp; 623&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
GSS_C_NO_OID; <br>
        &nbsp; 624&nbsp;&nbsp;&nbsp;&nbsp; } <br>
        &nbsp; 625&nbsp;&nbsp;&nbsp;&nbsp; cOid-&gt;length = 
(*env)-&gt;GetArrayLength(env,
        jbytes) - 2; <br>
        &nbsp; 626&nbsp;&nbsp;&nbsp;&nbsp; cOid-&gt;elements = 
malloc(cOid-&gt;length); <br>
        &nbsp; 627&nbsp;&nbsp;&nbsp;&nbsp; if(cOid-&gt;elements == NULL) 
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ same as above
        ] <br>
        &nbsp; 628&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
throwOutOfMemoryError(env,NULL); <br>
        &nbsp; 629&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; free(cOid); 
<br>
        &nbsp; 630&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
GSS_C_NO_OID; <br>
        &nbsp; 631&nbsp;&nbsp;&nbsp;&nbsp; } <br>
        <br>
        src/share/native/sun/security/smartcardio/pcsc.c <br>
        src/solaris/native/sun/security/smartcardio/pcsc_md.c <br>
        <br>
        &nbsp; It is kinda weird to have #ifdef WIN32 for these. It really
        seems <br>
        &nbsp; that these functions should be moved up to the shared pcsc.c <br>
        &nbsp; and externed from platform specific code, or an addition of <br>
        &nbsp; pcsc.h that declares the definitions. <br>
        <br>
        src/solaris/native/com/sun/security/auth/module/Solaris.c <br>
        <br>
        &nbsp; The comment is strange <br>
        &nbsp; 34 /* <br>
        &nbsp; 35&nbsp; *&nbsp; ** Throws a Java Exception by name <br>
        &nbsp; 36&nbsp; *&nbsp;&nbsp; **/ <br>
        <br>
        src/solaris/native/com/sun/security/auth/module/Unix.c <br>
        <br>
        &nbsp; Strange comment ( as above ). Also, why is there a need to for
        <br>
        &nbsp; #ifndef&nbsp; __solaris__ ?? <br>
        <br>
        -Chris. <br>
        <br>
        On 02/18/2013 04:09 PM, John Zavgren wrote: <br>
        <blockquote>Greetings: <br>
          I posted a new webrev image. <br>
          <a class="moz-txt-link-freetext" 
href="http://cr.openjdk.java.net/%7Ejzavgren/8007607/webrev.04/"; 
target="_blank">http://cr.openjdk.java.net/~jzavgren/8007607/webrev.04/</a>
          <br>
          <a class="moz-txt-link-rfc2396E" 
href="http://cr.openjdk.java.net/%7Ejzavgren/8007607/webrev.04/"; 
target="_blank">&lt;http://cr.openjdk.java.net/%7Ejzavgren/8007607/webrev.04/&gt;</a>
          <br>
          <br>
          The code now throws an OOM exception when *alloc() fails, and
          the <br>
          callers of procedures that call procedures that throw it,
          check for it. <br>
          <br>
          John <br>
          <br>
          On 02/12/2013 11:03 AM, Dmitry Samersoff wrote: <br>
          <blockquote>John, <br>
            <br>
            Changing everything for throw OOM is the right goal but it&#39;s
            a huge work <br>
            to do - it&#39;s meaningless to throw OOM if all callers doesn&#39;t
            check for <br>
            exception. <br>
            <br>
            I&#39;m in doubt it could be done all at once and probably this
            problem <br>
            should go to the huge TODO pile. <br>
            <br>
            So I&#39;m speaking about *one particular case*, where returned
            value could <br>
            lead to misinterpretation of security context and lead to
            security <br>
            vulnerability or subtle bug. <br>
            <br>
            We have to throw OOM there and change all callers as well
            for this case. <br>
            <br>
            -Dmitry <br>
            <br>
            On 2013-02-12 19:51, John Zavgren wrote: <br>
            <blockquote>On 02/08/2013 01:34 PM, Dmitry
              Samersoff wrote: <br>
              <blockquote>John, <br>
                <br>
                <blockquote>Ideas? <br>
                </blockquote>
                It&#39;s a JNI so just throw OOM. <br>
                <br>
                -Dmitry <br>
                <br>
                <br>
                On 2013-02-08 21:38, John Zavgren wrote: <br>
                <blockquote>Although I agree that the name:
                  &quot;GSS_C_NO_CHANNEL_BINDINGS&quot; is <br>
                  misleading, <br>
                  I can&#39;t identify anything else that seems more
                  appropriate. <br>
                  <br>
                  The header file: <br>
                  
/jdk8-tl/jdk/src/share/native/sun/security/jgss/wrapper/gssapi.h

                  defines <br>
                  GSS_C_NO_CHANNEL_BINDINGS as follows: <br>
                  #define GSS_C_NO_CHANNEL_BINDINGS
                  ((gss_channel_bindings_t) 0) <br>
                  <br>
                  The symbol matches the prototype of the function: <br>
                  <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */* <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Utility routine which 
creates a
                  gss_channel_bindings_t structure <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * using the specified
                  org.ietf.jgss.ChannelBinding object. <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gss_channel_bindings_t 
getGSSCB(JNIEnv *env,
                  jobject jcb) { <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
gss_channel_bindings_t cb; <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jobject jinetAddr; 
<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jbyteArray value; 
<br>
                  <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (jcb == NULL) { 
<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
GSS_C_NO_CHANNEL_BINDINGS; <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb = 
malloc(sizeof(struct
                  gss_channel_bindings_struct)); <br>
                  <br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cb 
== NULL) <br>
                  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return&nbsp; GSS_C_NO_CHANNEL_BINDINGS;* <br>
                  <br>
                  There doesn&#39;t appear to be anything in our set of
                  options that is more <br>
                  suggestive of a memory allocation failure and the
                  symbol: <br>
                  GSS_C_NO_CHANNEL_BINDINGS seems to be logically
                  correct. <br>
                  <br>
                  Ideas? <br>
                  <br>
                  On 02/06/2013 04:57 AM, Dmitry Samersoff wrote: <br>
                  <blockquote>John, <br>
                    <br>
                    Not sure GSS_C_NO_CHANNEL_BINDINGS; is correct
                    return value for this <br>
                    case. <br>
                    <br>
                    I&#39;m second to Valerie - it&#39;s better to throw OOM 
<br>
                    <br>
                    -Dmitry <br>
                    <br>
                    <br>
                    On 2013-02-06 03:44, John Zavgren wrote: <br>
                    <blockquote>Greetings: <br>
                      <br>
                      I modified the native code to eliminate potential
                      memory loss and <br>
                      crashes by checking the return values of malloc()
                      and realloc() calls. <br>
                      <br>
                      The webrev image of these changes is visible at: <br>
                      <a class="moz-txt-link-freetext" 
href="http://cr.openjdk.java.net/%7Ejzavgren/8007607/webrev.01/"; 
target="_blank">http://cr.openjdk.java.net/~jzavgren/8007607/webrev.01/</a>
                      <br>
                      <br>
                      Thanks! <br>
                      John Zavgren <br>
                      <br>
                    </blockquote>
                  </blockquote>
                  -- <br>
                  John Zavgren <br>
                  <a class="moz-txt-link-abbreviated" 
href="mailto:john.zavg...@oracle.com"; 
target="_blank">john.zavg...@oracle.com</a>
                  <br>
                  603-821-0904 <br>
                  US-Burlington-MA <br>
                  <br>
                </blockquote>
              </blockquote>
              When I change the procedures in the following files: <br>
              <br>
              src/share/native/sun/security/jgss/wrapper/GSSLibStub.c <br>
              src/share/native/sun/security/jgss/wrapper/NativeUtil.c <br>
              src/share/native/sun/security/smartcardio/pcsc.c <br>
              src/solaris/native/com/sun/security/auth/module/Solaris.c
              <br>
              src/solaris/native/com/sun/security/auth/module/Unix.c <br>
              <br>
              to fix inappropriate usages of malloc, realloc, etc.
              (e.g., not checking <br>
              the return value and referring to a NULL pointer and
              crashing) should I <br>
              modify every instance so that an OOM (Out Of Memory)
              exception is thrown <br>
              (before returning) whenever memory allocation fails? <br>
              <br>
              The exceptions would be thrown by a line of code that
              looks like: <br>
              <br>
              throwOutOfMemoryError(JNIEnv *env, const char *msg); <br>
              <br>
              where&nbsp; throwOutOfMemoryError(...) wraps something like
              this: <br>
              <br>
              
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jclass 
cls = (*env)-&gt;FindClass(env, name);
              <br>
              <br>
              
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if (cls != 0) /* Otherwise an exception
              has already been <br>
              thrown */ <br>
              
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (*env)-&gt;ThrowNew(env,
              cls, msg); <br>
              <br>
              If this is the right idea, what messages should I pass
              when an OOM <br>
              exception is thrown? <br>
              <br>
              Thanks! <br>
              John <br>
              <br>
            </blockquote>
            <br>
          </blockquote>
          <br>
          <br>
          -- <br>
          John Zavgren <br>
          <a class="moz-txt-link-abbreviated" 
href="mailto:john.zavg...@oracle.com"; 
target="_blank">john.zavg...@oracle.com</a>
          <br>
          603-821-0904 <br>
          US-Burlington-MA <br>
          <br>
        </blockquote>
      </blockquote>
      <br>
      <br>
      <pre class="moz-signature">-- 
John Zavgren
<a class="moz-txt-link-abbreviated" href="mailto:john.zavg...@oracle.com"; 
target="_blank">john.zavg...@oracle.com</a>
603-821-0904
US-Burlington-MA</pre>
    </blockquote>
    <br>
  </div>
</html>

Reply via email to