4242
4343#define RESULTS_FILE "validation_results.txt"
4444// Increment VALIDATOR_VERSION when a change is affecting the code.
45- #define VALIDATOR_VERSION "v2.0.0 " // Requires at least signed-video-framework v2.0.1
45+ #define VALIDATOR_VERSION "v2.0.1 " // Requires at least signed-video-framework v2.0.4
4646
4747typedef struct {
4848 GMainLoop * loop ;
@@ -51,7 +51,7 @@ typedef struct {
5151
5252 signed_video_t * sv ;
5353 signed_video_authenticity_t * auth_report ;
54- signed_video_product_info_t * product_info ;
54+ signed_video_product_info_t product_info ;
5555 char * version_on_signing_side ;
5656 char * this_version ;
5757 bool no_container ;
@@ -91,53 +91,19 @@ static gsize ongoing_obu_size = 0;
9191const bool parse_av1_manually = true;
9292#define METADATA_TYPE_USER_PRIVATE 25
9393
94- /* Helper function that copies a string and (re)allocates memory if necessary. */
95- static gint
96- reallocate_memory_and_copy_string (gchar * * dst_str , const gchar * src_str )
97- {
98- if (!dst_str ) return 0 ;
99- // If the |src_str| is a NULL pointer make sure to copy an empty string.
100- if (!src_str ) src_str = "" ;
101-
102- gsize dst_size = * dst_str ? strlen (* dst_str ) + 1 : 0 ;
103- const gsize src_size = strlen (src_str ) + 1 ;
104- gint success = 0 ;
105- if (src_size != dst_size ) {
106- gchar * new_dst_str = realloc (* dst_str , src_size );
107- if (!new_dst_str ) goto done ;
108-
109- * dst_str = new_dst_str ;
110- }
111- strcpy (* dst_str , src_str );
112- success = 1 ;
113-
114- done :
115- if (!success ) {
116- free (* dst_str );
117- * dst_str = NULL ;
118- }
119-
120- return success ;
121- }
122-
12394/* Helper function to copy signed_video_product_info_t. */
12495static gint
12596copy_product_info (signed_video_product_info_t * dst , const signed_video_product_info_t * src )
12697{
127- if (!src ) return 0 ;
128-
129- gint success = 0 ;
130- if (!reallocate_memory_and_copy_string (& dst -> hardware_id , src -> hardware_id )) goto done ;
131- if (!reallocate_memory_and_copy_string (& dst -> firmware_version , src -> firmware_version )) goto done ;
132- if (!reallocate_memory_and_copy_string (& dst -> serial_number , src -> serial_number )) goto done ;
133- if (!reallocate_memory_and_copy_string (& dst -> manufacturer , src -> manufacturer )) goto done ;
134- if (!reallocate_memory_and_copy_string (& dst -> address , src -> address )) goto done ;
135-
136- success = 1 ;
98+ if (!src || !dst ) return 0 ;
13799
138- done :
100+ strcpy (dst -> hardware_id , src -> hardware_id );
101+ strcpy (dst -> firmware_version , src -> firmware_version );
102+ strcpy (dst -> serial_number , src -> serial_number );
103+ strcpy (dst -> manufacturer , src -> manufacturer );
104+ strcpy (dst -> address , src -> address );
139105
140- return success ;
106+ return 1 ;
141107}
142108
143109static void
@@ -415,13 +381,7 @@ on_new_sample_from_sink(GstElement *elt, ValidationData *data)
415381 }
416382 strcat (result , data -> auth_report -> latest_validation .validation_str );
417383 post_validation_result_message (sink , bus , result );
418- // Allocate memory for |product_info| the first time it will be copied from the authenticity
419- // report.
420- if (!data -> product_info ) {
421- data -> product_info =
422- (signed_video_product_info_t * )g_malloc0 (sizeof (signed_video_product_info_t ));
423- }
424- if (!copy_product_info (data -> product_info , & (data -> auth_report -> product_info ))) {
384+ if (!copy_product_info (& (data -> product_info ), & (data -> auth_report -> product_info ))) {
425385 g_warning ("product info could not be transfered from authenticity report" );
426386 }
427387 // Allocate memory and copy version strings.
@@ -538,15 +498,11 @@ on_source_message(GstBus __attribute__((unused)) *bus, GstMessage *message, Vali
538498 fprintf (f , "-----------------------------\n" );
539499 fprintf (f , "\nProduct Info\n" );
540500 fprintf (f , "-----------------------------\n" );
541- if (data -> product_info ) {
542- fprintf (f , "Hardware ID: %s\n" , data -> product_info -> hardware_id );
543- fprintf (f , "Serial Number: %s\n" , data -> product_info -> serial_number );
544- fprintf (f , "Firmware version: %s\n" , data -> product_info -> firmware_version );
545- fprintf (f , "Manufacturer: %s\n" , data -> product_info -> manufacturer );
546- fprintf (f , "Address: %s\n" , data -> product_info -> address );
547- } else {
548- fprintf (f , "NOT PRESENT!\n" );
549- }
501+ fprintf (f , "Hardware ID: %s\n" , data -> product_info .hardware_id );
502+ fprintf (f , "Serial Number: %s\n" , data -> product_info .serial_number );
503+ fprintf (f , "Firmware version: %s\n" , data -> product_info .firmware_version );
504+ fprintf (f , "Manufacturer: %s\n" , data -> product_info .manufacturer );
505+ fprintf (f , "Address: %s\n" , data -> product_info .address );
550506 fprintf (f , "-----------------------------\n" );
551507 fprintf (f , "\nSigned Video timestamps\n" );
552508 fprintf (f , "-----------------------------\n" );
@@ -758,7 +714,6 @@ main(int argc, char **argv)
758714 if (data -> source ) gst_object_unref (data -> source );
759715 g_main_loop_unref (data -> loop );
760716 signed_video_free (data -> sv );
761- g_free (data -> product_info );
762717 g_free (data -> this_version );
763718 g_free (data -> version_on_signing_side );
764719 g_free (data );
0 commit comments