mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
				synced 2025-11-04 14:03:16 +00:00 
			
		
		
		
	[ipaccess] Verify the size part of the header
This commit is contained in:
		@@ -52,6 +52,7 @@ static char more_magic[] = { 0x10, 0x02, 0x00, 0x0 };
 | 
				
			|||||||
static void analyze_file(int fd)
 | 
					static void analyze_file(int fd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct sdp_firmware *firmware_header;
 | 
						struct sdp_firmware *firmware_header;
 | 
				
			||||||
 | 
						struct stat stat;
 | 
				
			||||||
	char buf[4096];
 | 
						char buf[4096];
 | 
				
			||||||
	int rc;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,6 +81,17 @@ static void analyze_file(int fd)
 | 
				
			|||||||
	printf("text2: %.64s\n", firmware_header->text2);
 | 
						printf("text2: %.64s\n", firmware_header->text2);
 | 
				
			||||||
	printf("time: %.8s\n", firmware_header->time);
 | 
						printf("time: %.8s\n", firmware_header->time);
 | 
				
			||||||
	printf("date: %.8s\n", firmware_header->date);
 | 
						printf("date: %.8s\n", firmware_header->date);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* verify the file */
 | 
				
			||||||
 | 
						if (fstat(fd, &stat) == -1) {
 | 
				
			||||||
 | 
							perror("Can not stat the file");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ntohl(firmware_header->file_length) != stat.st_size) {
 | 
				
			||||||
 | 
							fprintf(stderr, "The filesize and the header do not match.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char** argv)
 | 
					int main(int argc, char** argv)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user