Browse Source

Added debug statements.

Don't crash when called on an uninitialised chap structure; this
allows us to avoid extra checks within iscsi.c to make sure that we
receive the CHAP_XXX keys in a sensible order.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
d37f82509f
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      src/crypto/chap.c

+ 16
- 1
src/crypto/chap.c View File

51
 	assert ( chap->digest_context == NULL );
51
 	assert ( chap->digest_context == NULL );
52
 	assert ( chap->response == NULL );
52
 	assert ( chap->response == NULL );
53
 
53
 
54
+	DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name );
55
+
54
 	state_len = ( digest->context_len + digest->digest_len );
56
 	state_len = ( digest->context_len + digest->digest_len );
55
 	state = malloc ( state_len );
57
 	state = malloc ( state_len );
56
-	if ( ! state )
58
+	if ( ! state ) {
59
+		DBG ( "CHAP %p could not allocate %d bytes for state\n",
60
+		      chap, state_len );
57
 		return -ENOMEM;
61
 		return -ENOMEM;
62
+	}
58
 	
63
 	
59
 	chap->digest = digest;
64
 	chap->digest = digest;
60
 	chap->digest_context = state;
65
 	chap->digest_context = state;
76
 	assert ( chap->digest != NULL );
81
 	assert ( chap->digest != NULL );
77
 	assert ( chap->digest_context != NULL );
82
 	assert ( chap->digest_context != NULL );
78
 
83
 
84
+	if ( ! chap->digest )
85
+		return;
86
+
79
 	chap->digest->update ( chap->digest_context, data, len );
87
 	chap->digest->update ( chap->digest_context, data, len );
80
 }
88
 }
81
 
89
 
92
 	assert ( chap->digest_context != NULL );
100
 	assert ( chap->digest_context != NULL );
93
 	assert ( chap->response != NULL );
101
 	assert ( chap->response != NULL );
94
 
102
 
103
+	DBG ( "CHAP %p responding to challenge\n", chap );
104
+
105
+	if ( ! chap->digest )
106
+		return;
107
+
95
 	chap->digest->finish ( chap->digest_context, chap->response );
108
 	chap->digest->finish ( chap->digest_context, chap->response );
96
 }
109
 }
97
 
110
 
103
 void chap_finish ( struct chap_challenge *chap ) {
116
 void chap_finish ( struct chap_challenge *chap ) {
104
 	void *state = chap->digest_context;
117
 	void *state = chap->digest_context;
105
 
118
 
119
+	DBG ( "CHAP %p finished\n", chap );
120
+
106
 	free ( state );
121
 	free ( state );
107
 	memset ( chap, 0, sizeof ( *chap ) );
122
 	memset ( chap, 0, sizeof ( *chap ) );
108
 }
123
 }

Loading…
Cancel
Save