avb: Fix AvbSlotVerifyData->cmdline might be NULL

When AVB_VBMETA_IMAGE_FLAGS_VERIFICATION_DISABLED is set,
AvbSlotVerifyData->cmdline should be a NUL-terminated string
instead of NULL.

Bug: 119551429
Test: atest libavb_host_unittest

Git-repo: https://source.codeaurora.org/quic/la/platform/external/avb
Git-Commit: 9ba3b6613b4e5130fa01a11d984c6b5f0eb3af05

Change-Id: I07d8db24ace8bdd9bdeadf46803a2be36d2436a8
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);