title: X509_NAME_get_text_by_NID returns CN with number as text
body: <p>When I issue the following command:</p>
  
  <pre><code>cn[(sizeof cn) - 1] = 0;
  if (X509_NAME_get_text_by_NID(subj_p, NID_commonName,
                                cn, (sizeof cn) - 1) &lt;= 0) {
      fprintf(stderr, "Subject has no CN\n");
      return -1;
  }
  if (strncasecmp(cn, options.server_p, sizeof cn) != 0) {
      fprintf(stderr, "Subject CN mismatch (%s != %s)\n",
              options.server_p, cn);
      return -1;
  }
  </code></pre>
  
  <p>Where <code>options.server_p</code> is <code>a1.accessmylan.com</code></p>
  
  <p>I get the following error:</p>
  
  <pre><code>Subject CN mismatch (b1.accessmylan.com != BONE.ACCESSMYLAN.COM)
  </code></pre>
  
  <p>And if I try with a different server I get:</p>
  
  <pre><code>Subject CN mismatch (a1.accessmylan.com != aone.ACCESSMYLAN.COM)
  </code></pre>
  
  <p>Does anybody know why this might happen and / or how to resolve it? Thanks!</p>