2727#include <conio.h>
2828#include <time.h>
2929#include <wchar.h>
30+ #include <string.h>
3031#else
3132#include <unistd.h>
3233#include <wchar.h>
@@ -130,7 +131,7 @@ typedef struct _smbios_table_recording
130131#define PASS_THRU_OFFSET (ACPI_PMTT_OFFSET + ACPI_PMTT_SIZE) //40k
131132
132133int g_pass_thru_cnt = 0 ;
133- size_t g_pass_thru_playback_offset = 0 ;
134+ long g_pass_thru_playback_offset = 0 ;
134135
135136#define REC_FILE_PATH g_recording_fullpath
136137#define PLAYBACK_ENABLED () g_playback_mode
@@ -206,7 +207,6 @@ EFI_STATUS init_record_file(char * recording_file_path)
206207EFI_STATUS update_record_size (RecordType type , FILE * file_stream , UINT32 size , BOOLEAN increment )
207208{
208209 recording_file rc ;
209- UINT32 offset ;
210210
211211 //seek to the begining of the file
212212 if (0 != fseek (file_stream , 0 , SEEK_SET ))
@@ -305,13 +305,13 @@ EFI_STATUS seek_to_record_offset(RecordType type, FILE * file_stream, UINT32 *re
305305 if (0 != fseek (file_stream , 0 , SEEK_SET ))
306306 {
307307 NVDIMM_ERR ("Failed seeking to the begining of the file\n" );
308- return -1 ;
308+ return EFI_DEVICE_ERROR ;
309309 }
310310
311311 if (1 != fread (& rc , sizeof (recording_file ), 1 , file_stream ))
312312 {
313313 NVDIMM_ERR ("Failed to read the recording file header\n" );
314- return -1 ;
314+ return EFI_DEVICE_ERROR ;
315315 }
316316
317317 switch (type )
@@ -338,14 +338,14 @@ EFI_STATUS seek_to_record_offset(RecordType type, FILE * file_stream, UINT32 *re
338338 break ;
339339 default :
340340 NVDIMM_ERR ("Unknown record type\n" );
341- return -1 ;
341+ return EFI_INVALID_PARAMETER ;
342342 }
343343
344344 //seek to the begining of the record type partition
345345 if (0 != fseek (file_stream , offset , SEEK_SET ))
346346 {
347347 NVDIMM_ERR ("Failed seeking to the begining of the file\n" );
348- return -1 ;
348+ return EFI_DEVICE_ERROR ;
349349 }
350350 return EFI_SUCCESS ;
351351}
@@ -539,7 +539,6 @@ passthru_record_finalize(
539539 EFI_STATUS PassthruReturnCode
540540)
541541{
542- EFI_STATUS Rc = EFI_SUCCESS ;
543542 UINT32 total_write_sz = 0 ;
544543 if (!RECORD_ENABLED ())
545544 {
@@ -701,18 +700,21 @@ save_table_to_file(
701700 if (EFI_SUCCESS != (Rc = seek_to_record_offset (type , f_ptr , & record_size )))
702701 {
703702 NVDIMM_ERR ("Failed seeking to the ACPI partition\n" );
704- return Rc ;
703+ goto Finish ;
705704 }
706705
707706 if (table && 1 != fwrite (table , table -> Length , 1 , f_ptr ))
708707 {
709708 Rc = EFI_END_OF_FILE ;
709+ goto Finish ;
710710 }
711711
712712 if (table )
713713 {
714714 Rc = update_record_size (type , f_ptr , table -> Length , FALSE);
715715 }
716+
717+ Finish :
716718 fclose (f_ptr );
717719 return Rc ;
718720}
@@ -741,7 +743,7 @@ load_table_from_file(
741743 if (EFI_SUCCESS != (Rc = seek_to_record_offset (type , f_ptr , & size )))
742744 {
743745 NVDIMM_ERR ("Failed seeking to the ACPI partition\n" );
744- return Rc ;
746+ goto Finish ;
745747 }
746748
747749 if (!size )
@@ -763,6 +765,7 @@ load_table_from_file(
763765 }
764766 }
765767
768+ Finish :
766769 fclose (f_ptr );
767770 return Rc ;
768771}
@@ -883,8 +886,7 @@ GetFirstAndBoundSmBiosStructPointer(
883886 OUT SMBIOS_VERSION * pSmbiosVersion
884887)
885888{
886- EFI_STATUS ReturnCode = EFI_SUCCESS ;;
887- int rc = 0 ;
889+ EFI_STATUS ReturnCode = EFI_SUCCESS ;
888890 FILE * f_ptr ;
889891 smbios_table_recording recording ;
890892 UINT32 record_size = 0 ;
@@ -926,7 +928,7 @@ GetFirstAndBoundSmBiosStructPointer(
926928 NVDIMM_ERR ("Failed to write to recording file: %s\n" , REC_FILE_PATH );
927929 ReturnCode = EFI_END_OF_FILE ;
928930 }
929- update_record_size (RtSmbios , f_ptr , sizeof (smbios_table_recording ) + gSmbiosTableSize , FALSE);
931+ update_record_size (RtSmbios , f_ptr , ( UINT32 )( sizeof (smbios_table_recording ) + gSmbiosTableSize ) , FALSE);
930932 }
931933 fclose (f_ptr );
932934 }
@@ -938,7 +940,7 @@ GetFirstAndBoundSmBiosStructPointer(
938940 {
939941 if (NULL == gSmbiosTable ) {
940942 //seek it to pass thru partition
941- if (EFI_SUCCESS != ( rc = seek_to_record_offset (RtSmbios , f_ptr , & record_size ) ))
943+ if (EFI_SUCCESS != seek_to_record_offset (RtSmbios , f_ptr , & record_size ))
942944 {
943945 NVDIMM_ERR ("Failed seeking to the SMBIOS partition\n" );
944946 ReturnCode = EFI_END_OF_FILE ;
@@ -950,9 +952,9 @@ GetFirstAndBoundSmBiosStructPointer(
950952 ReturnCode = EFI_END_OF_FILE ;
951953 }
952954
953- if (0 == recording .size )
955+ if (SMBIOS_SIZE < recording . size || 0 == recording .size )
954956 {
955- NVDIMM_ERR ("SMBIOS table in file %s reports size of 0 .\n" , REC_FILE_PATH );
957+ NVDIMM_ERR ("SMBIOS table in file %s reports size of %d .\n" , REC_FILE_PATH , recording . size );
956958 ReturnCode = EFI_END_OF_FILE ;
957959 }
958960 else
0 commit comments