Răsfoiți Sursa

Only add '/' to path conditionally, and ensure sufficient space.

saybur 2 ani în urmă
părinte
comite
fba8ab4cb6
1 a modificat fișierele cu 3 adăugiri și 3 ștergeri
  1. 3 3
      src/ZuluSCSI_disk.cpp

+ 3 - 3
src/ZuluSCSI_disk.cpp

@@ -664,7 +664,7 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
             logmsg("Image directory was empty for ID", target_idx);
             return 0;
         }
-        else if (buflen < nextlen + dirlen + 1)
+        else if (buflen < nextlen + dirlen + 2)
         {
             logmsg("Directory '", dirname, "' and file '", nextname, "' exceed allowed length");
             return 0;
@@ -673,8 +673,8 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
         {
             // construct a return value
             strncpy(buf, dirname, buflen);
-            buf[dirlen] = '/';
-            strncpy(buf + dirlen + 1, nextname, buflen - dirlen - 1);
+            if (buf[strlen(buf) - 1] != '/') strcat(buf, "/");
+            strcat(buf, nextname);
             return dirlen + nextlen;
         }
     }