Browse Source

[efi] Add excessive sanity checks into efi_debug functions

Try very hard to avoid ever doing something invalid while attempting
to generate a debug message.

Debugged-by: Curtis Larsen <larsen@dixie.edu>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
f207176987
1 changed files with 53 additions and 3 deletions
  1. 53
    3
      src/interface/efi/efi_debug.c

+ 53
- 3
src/interface/efi/efi_debug.c View File

168
 	} u;
168
 	} u;
169
 	unsigned int i;
169
 	unsigned int i;
170
 
170
 
171
+	/* Sanity check */
172
+	if ( ! guid )
173
+		return NULL;
174
+
171
 	/* Check for a match against well-known GUIDs */
175
 	/* Check for a match against well-known GUIDs */
172
 	for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) /
176
 	for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) /
173
 			    sizeof ( efi_well_known_guids[0] ) ) ; i++ ) {
177
 			    sizeof ( efi_well_known_guids[0] ) ) ; i++ ) {
224
 	EFI_STATUS efirc;
228
 	EFI_STATUS efirc;
225
 	int rc;
229
 	int rc;
226
 
230
 
231
+	/* Sanity check */
232
+	if ( ( ! handle ) || ( ! protocol ) ) {
233
+		printf ( "EFI could not retrieve openers for %s on %p\n",
234
+			 efi_guid_ntoa ( protocol ), handle );
235
+		return;
236
+	}
237
+
227
 	/* Retrieve list of openers */
238
 	/* Retrieve list of openers */
228
 	if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
239
 	if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
229
 						     &count ) ) != 0 ) {
240
 						     &count ) ) != 0 ) {
268
 	EFI_STATUS efirc;
279
 	EFI_STATUS efirc;
269
 	int rc;
280
 	int rc;
270
 
281
 
282
+	/* Sanity check */
283
+	if ( ! handle ) {
284
+		printf ( "EFI could not retrieve protocols for %p\n", handle );
285
+		return;
286
+	}
287
+
271
 	/* Retrieve list of protocols */
288
 	/* Retrieve list of protocols */
272
 	if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
289
 	if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
273
 						&count ) ) != 0 ) {
290
 						&count ) ) != 0 ) {
301
 	static char text[256];
318
 	static char text[256];
302
 	CHAR16 *wtext;
319
 	CHAR16 *wtext;
303
 
320
 
304
-	/* Convert path to a textual representation */
305
-	if ( ! efidpt )
321
+	/* Sanity checks */
322
+	if ( ! efidpt ) {
323
+		DBG ( "[No DevicePathToText]" );
324
+		return NULL;
325
+	}
326
+	if ( ! path ) {
327
+		DBG ( "[NULL DevicePath]" );
306
 		return NULL;
328
 		return NULL;
329
+	}
330
+
331
+	/* Convert path to a textual representation */
307
 	wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
332
 	wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
308
 	if ( ! wtext )
333
 	if ( ! wtext )
309
 		return NULL;
334
 		return NULL;
328
 	CHAR16 *driver_name;
353
 	CHAR16 *driver_name;
329
 	EFI_STATUS efirc;
354
 	EFI_STATUS efirc;
330
 
355
 
356
+	/* Sanity check */
357
+	if ( ! wtf ) {
358
+		DBG ( "[NULL ComponentName2]" );
359
+		return NULL;
360
+	}
361
+
331
 	/* Try "en" first; if that fails then try the first language */
362
 	/* Try "en" first; if that fails then try the first language */
332
 	if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
363
 	if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
333
 					      &driver_name ) ) != 0 ) &&
364
 					      &driver_name ) ) != 0 ) &&
350
 static const char *
381
 static const char *
351
 efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
382
 efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
352
 	static char buf[32];
383
 	static char buf[32];
353
-	EFI_IMAGE_DOS_HEADER *dos = loaded->ImageBase;
384
+	EFI_IMAGE_DOS_HEADER *dos;
354
 	EFI_IMAGE_OPTIONAL_HEADER_UNION *pe;
385
 	EFI_IMAGE_OPTIONAL_HEADER_UNION *pe;
355
 	EFI_IMAGE_OPTIONAL_HEADER32 *opt32;
386
 	EFI_IMAGE_OPTIONAL_HEADER32 *opt32;
356
 	EFI_IMAGE_OPTIONAL_HEADER64 *opt64;
387
 	EFI_IMAGE_OPTIONAL_HEADER64 *opt64;
367
 	char *name;
398
 	char *name;
368
 	char *tmp;
399
 	char *tmp;
369
 
400
 
401
+	/* Sanity check */
402
+	if ( ! loaded ) {
403
+		DBG ( "[NULL LoadedImage]" );
404
+		return NULL;
405
+	}
406
+
370
 	/* Parse DOS header */
407
 	/* Parse DOS header */
408
+	dos = loaded->ImageBase;
371
 	if ( ! dos ) {
409
 	if ( ! dos ) {
372
 		DBG ( "[Missing DOS header]" );
410
 		DBG ( "[Missing DOS header]" );
373
 		return NULL;
411
 		return NULL;
462
 static const char *
500
 static const char *
463
 efi_first_loaded_image_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
501
 efi_first_loaded_image_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
464
 
502
 
503
+	/* Sanity check */
504
+	if ( ! loaded ) {
505
+		DBG ( "[NULL LoadedImage]" );
506
+		return NULL;
507
+	}
508
+
465
 	return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
509
 	return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
466
 }
510
 }
467
 
511
 
474
 static const char *
518
 static const char *
475
 efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
519
 efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
476
 
520
 
521
+	/* Sanity check */
522
+	if ( ! loaded ) {
523
+		DBG ( "[NULL LoadedImage]" );
524
+		return NULL;
525
+	}
526
+
477
 	return efi_devpath_text ( loaded->FilePath );
527
 	return efi_devpath_text ( loaded->FilePath );
478
 }
528
 }
479
 
529
 

Loading…
Cancel
Save