oor: Don't accept modified boot images by default
authorjb881122 <joeybeattie5@gmail.com>
Fri, 26 Apr 2024 17:14:50 +0000 (12:14 -0500)
committerNolen Johnson <johnsonnolen@gmail.com>
Fri, 26 Apr 2024 17:46:05 +0000 (17:46 +0000)
Change-Id: Ic222908d63e640dcb896bb44777a914c9d412be5

oor/src/bl_check.c

index ec8953e4d4ffee2aa1919023708596b8a6113bcc..5d3fb67471785dd13e29327877d90a22f8903123 100644 (file)
@@ -8,6 +8,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef CRC_PERMISSIVE
+
 char *find_bytes(char *mem, size_t mem_len, char *to_find, size_t to_find_len) {
     char *ret = NULL;
 
@@ -59,21 +61,6 @@ out:
     return ret;
 }
 
-bootloader_config *get_config_from_crc(char *bl_code, size_t bl_code_len) {
-    bootloader_config *config = NULL;
-    uint32_t bl_crc = 0;
-
-    bl_crc = crc32(bl_code, bl_code_len);
-    for(size_t i = 0; i < num_configs; i++) {
-        if(configs[i].code_crc == bl_crc) {
-            config = &configs[i];
-            break;
-        }
-    }
-
-    return config;
-}
-
 char bl_equals_str[] = "androidboot.bootloader=%s";
 
 bootloader_config *get_config_from_string(char *bl_code, size_t bl_code_len) {
@@ -98,16 +85,35 @@ out:
     return config;
 }
 
-bootloader_config *get_config(char *bl_code, size_t bl_code_len) {
-    bootloader_config *ret = NULL;
+#endif /* CRC_PERMISSIVE */
 
-    if(bl_code_len < 0x40000) {
-        goto out;
+bootloader_config *get_config_from_crc(char *bl_code, size_t bl_code_len) {
+    bootloader_config *config = NULL;
+    uint32_t bl_crc = 0;
+
+    bl_crc = crc32(bl_code, bl_code_len);
+    for(size_t i = 0; i < num_configs; i++) {
+        if(configs[i].code_crc == bl_crc) {
+            config = &configs[i];
+            break;
+        }
     }
 
+    return config;
+}
+
+bootloader_config *get_config(char *bl_code, size_t bl_code_len) {
+    bootloader_config *ret = NULL;
+
     ret = get_config_from_crc(bl_code, bl_code_len);
 
+#ifdef CRC_PERMISSIVE
     if(!ret) {
+        /* Make sure too-small bootloaders fail gracefully */
+        if(bl_code_len < 0x40000) {
+            goto out;
+        }
+
         ret = get_config_from_string(bl_code, bl_code_len);
         if(ret) {
             printf("WARNING: CRC Mismatch\n");
@@ -115,6 +121,7 @@ bootloader_config *get_config(char *bl_code, size_t bl_code_len) {
     }
 
 out:
+#endif
     if(ret) {
         printf("Bootloader found: %s\n", ret->name);
     } else {