26
26
27
27
#include "netdissect-stdinc.h"
28
28
29
+ #define ND_LONGJMP_FROM_TCHECK
29
30
#include "netdissect.h"
30
31
#include "extract.h"
31
32
@@ -149,7 +150,7 @@ static const struct tok eap_aka_subtype_values[] = {
149
150
void
150
151
eap_print (netdissect_options * ndo ,
151
152
const u_char * cp ,
152
- u_int length )
153
+ const u_int length )
153
154
{
154
155
u_int type , subtype , len ;
155
156
u_int count ;
@@ -158,6 +159,7 @@ eap_print(netdissect_options *ndo,
158
159
ndo -> ndo_protocol = "eap" ;
159
160
type = GET_U_1 (cp );
160
161
len = GET_BE_U_2 (cp + 2 );
162
+ ND_ICHECK_U (len , < , 4 );
161
163
if (len != length ) {
162
164
/*
163
165
* Probably a fragment; in some cases the fragmentation might
@@ -173,19 +175,12 @@ eap_print(netdissect_options *ndo,
173
175
type ,
174
176
GET_U_1 ((cp + 1 )),
175
177
len );
176
- if (len < 4 ) {
177
- ND_PRINT (" (too short for EAP header)" );
178
- return ;
179
- }
180
178
181
179
ND_TCHECK_LEN (cp , len );
182
180
183
181
if (type == EAP_REQUEST || type == EAP_RESPONSE ) {
184
182
/* RFC 3748 Section 4.1 */
185
- if (len < 5 ) {
186
- ND_PRINT (" (too short for EAP request/response)" );
187
- return ;
188
- }
183
+ ND_ICHECK_U (len , < , 5 );
189
184
subtype = GET_U_1 (cp + 4 );
190
185
ND_PRINT ("\n\t\t Type %s (%u)" ,
191
186
tok2str (eap_type_values , "unknown" , subtype ),
@@ -202,10 +197,7 @@ eap_print(netdissect_options *ndo,
202
197
203
198
case EAP_TYPE_NOTIFICATION :
204
199
/* According to RFC 3748, there must be at least one octet of message */
205
- if (len < 6 ) {
206
- ND_PRINT (" (too short for EAP Notification request/response)" );
207
- return ;
208
- }
200
+ ND_ICHECK_U (len , < , 6 );
209
201
ND_PRINT (", Notification: " );
210
202
nd_printjnp (ndo , cp + 5 , len - 5 );
211
203
break ;
@@ -216,10 +208,7 @@ eap_print(netdissect_options *ndo,
216
208
* the desired authentication
217
209
* type one octet per type
218
210
*/
219
- if (len < 6 ) {
220
- ND_PRINT (" (too short for EAP Legacy NAK request/response)" );
221
- return ;
222
- }
211
+ ND_ICHECK_U (len , < , 6 );
223
212
sep = "" ;
224
213
for (count = 5 ; count < len ; count ++ ) {
225
214
ND_PRINT ("%s %s (%u)" , sep ,
@@ -231,10 +220,7 @@ eap_print(netdissect_options *ndo,
231
220
232
221
case EAP_TYPE_TTLS :
233
222
case EAP_TYPE_TLS :
234
- if (len < 6 ) {
235
- ND_PRINT (" (too short for EAP TLS/TTLS request/response)" );
236
- return ;
237
- }
223
+ ND_ICHECK_U (len , < , 6 );
238
224
if (subtype == EAP_TYPE_TTLS )
239
225
ND_PRINT (" TTLSv%u" ,
240
226
EAP_TTLS_VERSION (GET_U_1 ((cp + 5 ))));
@@ -243,30 +229,21 @@ eap_print(netdissect_options *ndo,
243
229
GET_U_1 (cp + 5 ));
244
230
245
231
if (EAP_TLS_EXTRACT_BIT_L (GET_U_1 (cp + 5 ))) {
246
- if (len < 10 ) {
247
- ND_PRINT (" (too short for EAP TLS/TTLS request/response with length)" );
248
- return ;
249
- }
232
+ ND_ICHECK_U (len , < , 10 );
250
233
ND_PRINT (", len %u" , GET_BE_U_4 (cp + 6 ));
251
234
}
252
235
break ;
253
236
254
237
case EAP_TYPE_FAST :
255
- if (len < 6 ) {
256
- ND_PRINT (" (too short for EAP FAST request/response)" );
257
- return ;
258
- }
238
+ ND_ICHECK_U (len , < , 6 );
259
239
ND_PRINT (" FASTv%u" ,
260
240
EAP_TTLS_VERSION (GET_U_1 ((cp + 5 ))));
261
241
ND_PRINT (" flags [%s] 0x%02x" ,
262
242
bittok2str (eap_tls_flags_values , "none" , GET_U_1 ((cp + 5 ))),
263
243
GET_U_1 (cp + 5 ));
264
244
265
245
if (EAP_TLS_EXTRACT_BIT_L (GET_U_1 (cp + 5 ))) {
266
- if (len < 10 ) {
267
- ND_PRINT (" (too short for EAP FAST request/response with length)" );
268
- return ;
269
- }
246
+ ND_ICHECK_U (len , < , 10 );
270
247
ND_PRINT (", len %u" , GET_BE_U_4 (cp + 6 ));
271
248
}
272
249
@@ -275,10 +252,7 @@ eap_print(netdissect_options *ndo,
275
252
276
253
case EAP_TYPE_AKA :
277
254
case EAP_TYPE_SIM :
278
- if (len < 6 ) {
279
- ND_PRINT (" (too short for EAP SIM/AKA request/response)" );
280
- return ;
281
- }
255
+ ND_ICHECK_U (len , < , 6 );
282
256
ND_PRINT (" subtype [%s] 0x%02x" ,
283
257
tok2str (eap_aka_subtype_values , "unknown" , GET_U_1 ((cp + 5 ))),
284
258
GET_U_1 (cp + 5 ));
@@ -296,8 +270,9 @@ eap_print(netdissect_options *ndo,
296
270
}
297
271
}
298
272
return ;
299
- trunc :
300
- nd_print_trunc (ndo );
273
+
274
+ invalid :
275
+ nd_print_invalid (ndo );
301
276
}
302
277
303
278
void
@@ -309,7 +284,6 @@ eapol_print(netdissect_options *ndo,
309
284
310
285
ndo -> ndo_protocol = "eap" ;
311
286
eap = (const struct eap_frame_t * )cp ;
312
- ND_TCHECK_SIZE (eap );
313
287
eap_type = GET_U_1 (eap -> type );
314
288
315
289
ND_PRINT ("%s (%u) v%u, len %u" ,
@@ -326,17 +300,17 @@ eapol_print(netdissect_options *ndo,
326
300
switch (eap_type ) {
327
301
case EAP_FRAME_TYPE_PACKET :
328
302
if (eap_len == 0 )
329
- goto trunc ;
303
+ goto invalid ;
330
304
ND_PRINT (", " );
331
305
eap_print (ndo , cp , eap_len );
332
- return ;
306
+ break ;
333
307
case EAP_FRAME_TYPE_LOGOFF :
334
308
case EAP_FRAME_TYPE_ENCAP_ASF_ALERT :
335
309
default :
336
310
break ;
337
311
}
338
312
return ;
339
313
340
- trunc :
341
- nd_print_trunc (ndo );
314
+ invalid :
315
+ nd_print_invalid (ndo );
342
316
}
0 commit comments