1

学習用に次のエクスプロイト コードをコンパイルしようとしており、C のポインターについて調査しましたが、何度もコードを修正しようとしても、コンパイラ エラー メッセージに影響はありませんでした。誰かが私を正しい方向に向けることができれば幸いです.Cの経験はほとんどありません.

関連するエラー:

OFudge.c: In function ‘get_server_hello’:
OFudge.c:1009:5: warning: passing argument 2 of ‘d2i_X509’ from incompatible pointer
type [enabled by default]                                                                                         

行 1009:

ssl->x509=d2i_X509(NULL,&p,(long)cert_length);

機能全体:

void get_server_hello(ssl_conn* ssl)
{
    unsigned char buf[BUFSIZE];
    unsigned char *p, *end;
    int len;
    int server_version, cert_length, cs_length, conn_id_length;
    int found;

    if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) {
        printf("Server error: %s\n", ssl_error(ntohs(*(uint16_t*)&buf[1])));
        exit(1);
    }
    if (len < 11) {
        printf("get_server_hello: Packet too short (len = %d)\n", len);
        exit(1);
    }

    p = buf;

    if (*(p++) != SSL2_MT_SERVER_HELLO) {
        printf("get_server_hello: Expected SSL2 MT SERVER HELLO, got %x\n", (int)p[-1]);
        exit(1);
    }

    if (*(p++) != 0) {
        printf("get_server_hello: SESSION-ID-HIT is not 0\n");
        exit(1);
    }

    if (*(p++) != 1) {
        printf("get_server_hello: CERTIFICATE-TYPE is not SSL CT X509 CERTIFICATE\n");
        exit(1);
    }

    n2s(p, server_version);
    if (server_version != 2) {
        printf("get_server_hello: Unsupported server version %d\n", server_version);
        exit(1);
    }

    n2s(p, cert_length);
    n2s(p, cs_length);
    n2s(p, conn_id_length);

    if (len != 11 + cert_length + cs_length + conn_id_length) {
        printf("get_server_hello: Malformed packet size\n");
        exit(1);
    }

    /* read the server certificate */
    ssl->x509 = NULL;
    ssl->x509=d2i_X509(NULL,&p,(long)cert_length);
    if (ssl->x509 == NULL) {
        printf("get server hello: Cannot parse x509 certificate\n");
        exit(1);
    }

    if (cs_length % 3 != 0) {
        printf("get server hello: CIPHER-SPECS-LENGTH is not a multiple of 3\n");
        exit(1);
    }

    found = 0;
    for (end=p+cs_length; p < end; p += 3) {
        if ((p[0] == 0x01) && (p[1] == 0x00) && (p[2] == 0x80))
           found = 1;  /* SSL CK RC4 128 WITH MD5 */
    }

    if (!found) {
        printf("get server hello: Remote server does not support 128 bit RC4\n");
        exit(1);
    }

    if (conn_id_length > SSL2_MAX_CONNECTION_ID_LENGTH) {
        printf("get server hello: CONNECTION-ID-LENGTH is too long\n");
        exit(1);
    }

    /* The connection id is sent back to the server in the CLIENT FINISHED packet */
    ssl->conn_id_length = conn_id_length;
    memcpy(ssl->conn_id, p, conn_id_length);
}
4

1 に答える 1

0

コンパイラは、問題が何であるかを明確に示しました。どの引数が問題を引き起こしたかも教えてくれました。予想されるパラメーターの型と、引数として渡す型を単純に比較するのは難しいですか?

これによれば

http://www.openssl.org/docs/crypto/d2i_X509.html

関数はconst unsigned char **パラメーターを必要とします

X509 *d2i_X509(X509 **px, const unsigned char **in, int len);

代わりにを渡していunsigned char **ます。const unsigned char **unsigned char **は 2 つの異なる型であり、互いに暗黙的に変換することはできません。だから、ここにあなたのエラーがあります。

于 2012-12-21T20:34:36.160 に答える