Advertisement
Guest User

Debug

a guest
May 7th, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.69 KB | None | 0 0
  1.          
  2. //------------------------------------------------------------------------------------------
  3. //DEFINING 3 STRUCTURES HERE
  4. //------------------------------------------------------------------------------------------
  5. typedef struct _SslDecryptSession {
  6.     guchar _master_secret[SSL_MASTER_SECRET_LENGTH];
  7.     guchar _session_id[256];
  8.     guchar _client_random[32];
  9.     guchar _server_random[32];
  10.     StringInfo session_id;
  11.     StringInfo session_ticket;
  12.     StringInfo server_random;
  13.     StringInfo client_random;
  14.     StringInfo master_secret;
  15.     StringInfo handshake_data;
  16.     /* the data store for this StringInfo must be allocated explicitly with a capture lifetime scope */
  17.     StringInfo pre_master_secret;
  18.     guchar _server_data_for_iv[24];
  19.     StringInfo server_data_for_iv;
  20.     guchar _client_data_for_iv[24];
  21.     StringInfo client_data_for_iv;
  22.  
  23.     gint state;
  24.     SslCipherSuite cipher_suite;
  25.     SslDecoder *server;
  26.     SslDecoder *client;
  27.     SslDecoder *server_new;
  28.     SslDecoder *client_new;
  29. #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
  30.     gcry_sexp_t private_key;
  31. #endif
  32.     StringInfo psk;
  33.     guint16 version_netorder;
  34.     StringInfo app_data_segment;
  35.     SslSession session;
  36.  
  37. } SslDecryptSession;
  38.  
  39.  
  40. /* XXX Should we use GByteArray instead? */
  41. typedef struct _StringInfo {
  42.     guchar  *data;      /* Backing storage which may be larger than data_len */
  43.     guint    data_len;  /* Length of the meaningful part of data */
  44. } StringInfo
  45.  
  46. typedef struct _SslSession {
  47.     gint cipher;
  48.     gint compression;
  49.     guint32 version;
  50.     gint8 client_cert_type;
  51.     gint8 server_cert_type;
  52.  
  53.     /* The address/proto/port of the server as determined from heuristics
  54.      * (e.g. ClientHello) or set externally (via ssl_set_master_secret()). */
  55.     address srv_addr;
  56.     port_type srv_ptype;
  57.     guint srv_port;
  58.  
  59.     /* The Application layer protocol if known (for STARTTLS support) */
  60.     dissector_handle_t   app_handle;
  61.     guint32              last_nontls_frame;
  62.     gboolean             is_session_resumed;
  63. } SslSession;
  64.  
  65.  
  66. //------------------------------------------------------------------------------------------
  67. //Somewhere in the main function, The piece of code I am executing
  68. //------------------------------------------------------------------------------------------
  69.  
  70.         SslDecryptSession *ssl_session = malloc(sizeof(struct _SslDecryptSession ));
  71.          ssl_session->client_random.data = NULL;
  72.          ssl_session->server_random.data= NULL;
  73.         const u_char *payload;                  /* Packet payload */
  74.             //Case for client random
  75.             printf("Client Random ");
  76.             for (cs_id = 11; cs_id < 43; cs_id++){
  77.                     printf("%hhX", payload[cs_id] );
  78.             }
  79.             printf("\n");
  80.            
  81.  
  82.             cs_id=11;
  83.             ssl_session->client_random.data_len=32;
  84.             // Segmentation fault here
  85.             memcpy(ssl_session->client_random.data, payload[cs_id], 32);
  86.  
  87.  
  88. /* More error debug from gdb
  89.  
  90.  
  91. b 1985    // Putting a break point at line 1985 in my source code.
  92.      //Here this is eqvialent to line 83, that is "ssl_session->client_random.data_len=32;"
  93. Breakpoint 1 at 0x403878: file Newversion.c, line 1985.
  94.  
  95. run       //run the code in gdb
  96.  
  97. At breakpoint 1 the following info is in the variables
  98.  
  99.  
  100. p ssl_session
  101. $1 = (SslDecryptSession *) 0x60fc50   // I put some data in ssl_session->version_netorder earlier. So it is not null here. Everything works fine here
  102.  
  103. p ssl_session->client_random.data
  104. $2 = (guchar *) 0x0
  105.  
  106. p ssl_session->client_random.data_len
  107. $3 = 32
  108.  
  109. step  // Execute 1 more line in the code
  110.  
  111. // I reach at the memcpy line and I get this error then
  112.  
  113. Breakpoint 1, got_packet (args=0x0, header=0x7fffffffe2c0, packet=0x7ffff6939086 "P=\345\203\376\177") at Newversion.c:1995
  114. 1995                memcpy(ssl_session->client_random.data, payload[cs_id], 32);
  115. (gdb)
  116. (gdb) s
  117. __memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:27
  118. 27  ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S: No such file or directory.
  119. (gdb)
  120. 28  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  121. (gdb)
  122. 29  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  123. (gdb)
  124. 30  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  125. (gdb)
  126. 31  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  127. (gdb)
  128. 32  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  129. (gdb)
  130. 33  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  131. (gdb)
  132. 34  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  133. (gdb)
  134. 35  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  135. (gdb)
  136.  
  137. Program received signal SIGSEGV, Segmentation fault.
  138. __memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:35
  139. 35  in ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S
  140.  
  141.  
  142.  
  143. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement