]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
hs_serialized_database_info: check whole input
authorBoris Nagaev <bnagaev@gmail.com>
Sun, 29 May 2016 09:27:11 +0000 (12:27 +0300)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 03:27:44 +0000 (13:27 +1000)
Most lines of hs_serialized_database_info are not needed,
as the information is provided by db_decode_header.
Moreover, db_decode_header changes its first argument,
so it points to end of header after db_decode_header.

src/database.c

index 635a3b660fc510184e38ed76fb38a5557cd78ed9..a4e10c225b68b69fa7da379d899074c9845631b3 100644 (file)
@@ -458,33 +458,16 @@ hs_error_t hs_serialized_database_info(const char *bytes, size_t length,
     }
     *info = NULL;
 
-    if (!bytes || length < sizeof(struct hs_database)) {
-        return HS_INVALID;
-    }
-
-    const u32 *buf = (const u32 *)bytes;
-
-    u32 magic = unaligned_load_u32(buf++);
-    if (magic != HS_DB_MAGIC) {
-        return HS_INVALID;
+    // Decode and check the header
+    hs_database_t header;
+    hs_error_t ret = db_decode_header(&bytes, length, &header);
+    if (ret != HS_SUCCESS) {
+        return ret;
     }
 
-    u32 version = unaligned_load_u32(buf++);
-
-    buf++; /* length */
-
-    platform_t plat;
-    plat = unaligned_load_u64a(buf);
-    buf += 2;
-
-    buf++; /* crc */
-    buf++; /* reserved 0 */
-    buf++; /* reserved 1 */
-
-    const char *t_raw = (const char *)buf;
-    u32 mode = unaligned_load_u32(t_raw + offsetof(struct RoseEngine, mode));
+    u32 mode = unaligned_load_u32(bytes + offsetof(struct RoseEngine, mode));
 
-    return print_database_string(info, version, plat, mode);
+    return print_database_string(info, header.version, header.platform, mode);
 }
 
 HS_PUBLIC_API