vold: Avoid SIGSEGVs when fstab lacks /data

This change adds null-checks for all the places where cryptfs tries to
access the /data entry in fstab, to avoid crashes.

Bug: 80493321
Test: No crashes in Android-in-Chrome OS (which lacks /data in fstab)
Change-Id: Id6cdfe01cdd336cebf8afb9bdd07135811115182
Merged-In: Id6cdfe01cdd336cebf8afb9bdd07135811115182
diff --git a/cryptfs.cpp b/cryptfs.cpp
index e8bf3aa..4e325e6 100644
--- a/cryptfs.cpp
+++ b/cryptfs.cpp
@@ -1451,7 +1451,9 @@
         property_get("ro.crypto.readonly", ro_prop, "");
         if (strlen(ro_prop) > 0 && atoi(ro_prop)) {
             struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, DATA_MNT_POINT);
-            rec->flags |= MS_RDONLY;
+            if (rec) {
+                rec->flags |= MS_RDONLY;
+            }
         }
 
         /* If that succeeded, then mount the decrypted filesystem */
@@ -2061,6 +2063,10 @@
 
     if (how == CRYPTO_ENABLE_WIPE) {
         struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, DATA_MNT_POINT);
+        if (!rec) {
+            SLOGE("cryptfs_enable: missing %s entry in fstab\n", DATA_MNT_POINT);
+            return -1;
+        }
         int fs_type = get_fs_type(rec);
         if (fs_type < 0) {
             SLOGE("cryptfs_enable: unsupported fs type %s\n", rec->fs_type);
@@ -2917,7 +2923,7 @@
 int cryptfs_isConvertibleToFBE()
 {
     struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, DATA_MNT_POINT);
-    return fs_mgr_is_convertible_to_fbe(rec) ? 1 : 0;
+    return (rec && fs_mgr_is_convertible_to_fbe(rec)) ? 1 : 0;
 }
 
 int cryptfs_create_default_ftr(struct crypt_mnt_ftr* crypt_ftr, __attribute__((unused))int key_length)
@@ -2990,5 +2996,10 @@
                                        const char **filenames_mode_ret)
 {
     struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, DATA_MNT_POINT);
+    if (!rec) {
+        *contents_mode_ret = nullptr;
+        *filenames_mode_ret = nullptr;
+        return;
+    }
     fs_mgr_get_file_encryption_modes(rec, contents_mode_ret, filenames_mode_ret);
 }