You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: desmume/src/saves.cpp
+36-12Lines changed: 36 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -661,25 +661,27 @@ void scan_savestates()
661
661
structstat sbuf;
662
662
#endif
663
663
664
-
char filename[MAX_PATH + 1];
664
+
char filename[MAX_PATH] = {0};
665
665
path.getpathnoext(path.STATE_SLOTS, filename);
666
666
667
667
constsize_t filenameLen = strlen(filename);
668
-
constsize_t extLen = strlen(".ds");
669
668
constsize_t numberLen = strlen("-2147483648"); // Longest possible string length for a 32-bit int
669
+
constsize_t extLen = strlen(".ds") + numberLen;
670
+
constsize_t totalLen = filenameLen + extLen;
670
671
671
672
clear_savestates();
672
673
673
-
if ((filenameLen + extLen + numberLen) >= MAX_PATH)
674
+
if (totalLen >= MAX_PATH)
674
675
{
676
+
printf("Scan Save State ERROR: The file path is too long. (path length is %llu bytes, maximum length is %llu bytes)\n", (unsignedlonglong)totalLen, (unsignedlonglong)MAX_PATH);
constsize_t numberLen = strlen("-2147483648"); // Longest possible string length for a 32-bit int
710
+
constsize_t extLen = strlen(".ds") + numberLen;
711
+
constsize_t totalLen = filenameLen + extLen;
712
+
713
+
if (totalLen >= MAX_PATH)
714
+
{
715
+
printf("Save State ERROR: The file path is too long. (path length is %llu bytes, maximum length is %llu bytes)\n", (unsignedlonglong)totalLen, (unsignedlonglong)MAX_PATH);
constsize_t numberLen = strlen("-2147483648"); // Longest possible string length for a 32-bit int
756
+
constsize_t extLen = strlen(".ds") + numberLen;
757
+
constsize_t totalLen = filenameLen + extLen;
758
+
759
+
if (totalLen >= MAX_PATH)
760
+
{
761
+
printf("Load State ERROR: The file path is too long. (path length is %llu bytes, maximum length is %llu bytes)\n", (unsignedlonglong)totalLen, (unsignedlonglong)MAX_PATH);
762
+
return;
763
+
}
740
764
741
765
//save the state before we load the state, to give people a path for recovery in case they hit the wrong key
742
766
#ifdef HOST_WINDOWS
@@ -794,9 +818,9 @@ void loadstate_slot(int num)
794
818
795
819
}
796
820
}
797
-
798
-
if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ > MAX_PATH) return;
0 commit comments