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

Change-Id: I27616b217f01acf7e1196bacc023ea610117935c
diff --git a/libavb/avb_slot_verify.c b/libavb/avb_slot_verify.c
index 72f5091..75b26d6 100644
--- a/libavb/avb_slot_verify.c
+++ b/libavb/avb_slot_verify.c
@@ -1442,10 +1442,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 {
       /* If requested, manage dm-verity mode... */
@@ -1480,7 +1483,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 = avb_sub_cmdline(ops,
                                     slot_data->cmdline,
diff --git a/test/avb_slot_verify_unittest.cc b/test/avb_slot_verify_unittest.cc
index 829e9a6..e03c37e 100644
--- a/test/avb_slot_verify_unittest.cc
+++ b/test/avb_slot_verify_unittest.cc
@@ -2142,7 +2142,7 @@
     EXPECT_EQ("root=PARTUUID=1234-fake-guid-for:system_a",
               std::string(slot_data->cmdline));
   } else {
-    EXPECT_EQ(nullptr, slot_data->cmdline);
+    EXPECT_EQ("", std::string(slot_data->cmdline));
   }
 
   // Also make sure that it actually loads the boot and dtbo partitions.