Merge "avb: Fix AvbSlotVerifyData->cmdline might be NULL"
diff --git a/platform/msm_shared/avb/libavb/avb_slot_verify.c b/platform/msm_shared/avb/libavb/avb_slot_verify.c
index 8d0db6d..5818fa1 100644
--- a/platform/msm_shared/avb/libavb/avb_slot_verify.c
+++ b/platform/msm_shared/avb/libavb/avb_slot_verify.c
@@ -1412,10 +1412,13 @@
       if (has_system_partition(ops, ab_suffix)) {
         slot_data->cmdline =
             avb_strdup("root=PARTUUID=$(ANDROID_SYSTEM_PARTUUID)");
-        if (slot_data->cmdline == NULL) {
-          ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
-          goto fail;
-        }
+      } else {
+        // The |cmdline| field should be a NUL-terminated string.
+        slot_data->cmdline = avb_strdup("");
+      }
+      if (slot_data->cmdline == NULL) {
+        ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
+        goto fail;
       }
     } else {
       /* Add options - any failure in append_options() is either an
@@ -1433,7 +1436,7 @@
     }
 
     /* Substitute $(ANDROID_SYSTEM_PARTUUID) and friends. */
-    if (slot_data->cmdline != NULL) {
+    if (slot_data->cmdline != NULL && avb_strlen(slot_data->cmdline) != 0) {
       char* new_cmdline;
       new_cmdline = sub_cmdline(
           ops, slot_data->cmdline, ab_suffix, using_boot_for_vbmeta);