Browse Source

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

saybur 2 years ago
parent
commit
b54bf9065d
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/BlueSCSI_disk.cpp

+ 3 - 3
src/BlueSCSI_disk.cpp

@@ -652,7 +652,7 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
             log("Image directory was empty for ID", target_idx);
             return 0;
         }
-        else if (buflen < nextlen + dirlen + 1)
+        else if (buflen < nextlen + dirlen + 2)
         {
             log("Directory '", dirname, "' and file '", nextname, "' exceed allowed length");
             return 0;
@@ -661,8 +661,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;
         }
     }