Match maximum command line size for startup tracing.

Fix too small buffer for the startup property not accounting for the
prefix.

Bug: 131893397

Change-Id: Iad2398bc09c61b1144430bcbef58e5a832b85b0a
diff --git a/libc/bionic/malloc_heapprofd.cpp b/libc/bionic/malloc_heapprofd.cpp
index 2aeb9bf..5d3735d 100644
--- a/libc/bionic/malloc_heapprofd.cpp
+++ b/libc/bionic/malloc_heapprofd.cpp
@@ -143,22 +143,23 @@
   }
 }
 
+constexpr char kHeapprofdProgramPropertyPrefix[] = "heapprofd.enable.";
+constexpr size_t kHeapprofdProgramPropertyPrefixSize = sizeof(kHeapprofdProgramPropertyPrefix) - 1;
+constexpr size_t kMaxCmdlineSize = 512;
+
 static bool GetHeapprofdProgramProperty(char* data, size_t size) {
-  constexpr char prefix[] = "heapprofd.enable.";
-  // - 1 to skip nullbyte, which we will write later.
-  constexpr size_t prefix_size = sizeof(prefix) - 1;
-  if (size < prefix_size) {
+  if (size < kHeapprofdProgramPropertyPrefixSize) {
     error_log("%s: Overflow constructing heapprofd property", getprogname());
     return false;
   }
-  memcpy(data, prefix, prefix_size);
+  memcpy(data, kHeapprofdProgramPropertyPrefix, kHeapprofdProgramPropertyPrefixSize);
 
   int fd = open("/proc/self/cmdline", O_RDONLY | O_CLOEXEC);
   if (fd == -1) {
     error_log("%s: Failed to open /proc/self/cmdline", getprogname());
     return false;
   }
-  char cmdline[128];
+  char cmdline[kMaxCmdlineSize];
   ssize_t rd = read(fd, cmdline, sizeof(cmdline) - 1);
   close(fd);
   if (rd == -1) {
@@ -167,7 +168,7 @@
   }
   cmdline[rd] = '\0';
   char* first_arg = static_cast<char*>(memchr(cmdline, '\0', rd));
-  if (first_arg == nullptr || first_arg == cmdline + size - 1) {
+  if (first_arg == nullptr) {
     error_log("%s: Overflow reading cmdline", getprogname());
     return false;
   }
@@ -192,12 +193,12 @@
   }
 
   size_t name_size = static_cast<size_t>(first_arg - start);
-  if (name_size >= size - prefix_size) {
+  if (name_size >= size - kHeapprofdProgramPropertyPrefixSize) {
     error_log("%s: overflow constructing heapprofd property.", getprogname());
     return false;
   }
   // + 1 to also copy the trailing null byte.
-  memcpy(data + prefix_size, start, name_size + 1);
+  memcpy(data + kHeapprofdProgramPropertyPrefixSize, start, name_size + 1);
   return true;
 }
 
@@ -213,7 +214,7 @@
     return true;
   }
 
-  char program_property[128];
+  char program_property[kHeapprofdProgramPropertyPrefixSize + kMaxCmdlineSize];
   if (!GetHeapprofdProgramProperty(program_property,
                                    sizeof(program_property))) {
     return false;