Repository navigation
Fix bugs found by reading the merged v1.2.0 code - #27
Merged
Merged
Conversation
- ".." no longer climbs out of the GEMDRIVE folder. FatFs follows ".."
(FF_FS_RPATH is 2), so Dsetpath("..") at the drive's root made the
root of the card current, and every relative Fopen or Fdelete after
it acted on the whole card. Paths on the emulated drive are now
normalised before use, with ".." stopping at the root, in Dsetpath and
in every path a call turns into a card path. The normaliser is
md-drives-emulator's sdcard_normalizePath, with its segment count
bounded.
- Dsetpath, Fclose and Fdelete errors reach the program. The status was
written as a long and read with move.w, so the program got its sign
half: every error was -1. They are written as words, as
md-drives-emulator does for Dsetpath and Fclose.
- The end of a search is ENMFIL (-49), as with TOS, not EFILNF (-33).
- Fsfirst("NAME.*") finds NAME.TXT. The trailing ".*" that lets "*.*"
match folders was cut from every pattern, leaving "NAME", which only
a file called NAME matched. Fsfirst("C:*.BIN") no longer keeps "C:"
in the pattern.
- Ddelete only removes folders and Fdelete only files: both called
f_unlink, so Ddelete("FILE.TXT") deleted the file.
- Dfree caps the cluster counts so TOS's 32-bit byte count cannot wrap:
a 32 GB card showed its free space modulo 4 GiB, from
md-drives-emulator.
Every ROM3 sample whose high byte is $FF was taken as a debug byte, and a command frame's own words produce such samples whenever their m68k value has $7F in the high byte. A program writing a file through GEMDRIVE put one stray byte in the debug stream for every 256 bytes of a pattern rich in $7F. A sample is now a debug byte only while the parser is between frames: waiting for a header, or past its resync gap.
Nine more checks: the error codes of Dsetpath and Fclose, ".." at the drive's root, Fsfirst with "NAME.*" and with a drive letter, the code that ends a search, Ddelete of a file and Fdelete of a folder, and Dfree's free bytes as TOS multiplies them. Before the fixes just made they all failed in EmuMD; now GDTEST passes on an ST, an STE and a Mega STE.
- A backslash no longer escapes the GEMDRIVE folder. Paths were split into segments on '/' only, but FatFs takes '\' as a separator too and follows "..", so ?path=%5C.. listed the root of the card and a DELETE or PUT through "\..\" reached any file on it. '\' now separates folders exactly like '/', so the ST's own GAMES\ARKANOID still works, and the Runner's stored folder is always the normalised form, which keeps the status JSON valid. - An overwrite that is cut off no longer deletes the original. The file was truncated as the upload began and deleted when it failed; an overwrite is now written to UPLOAD~N.TMP in the same folder and replaces the original only once the whole body is on the card. - Listing a folder whose path is 48 characters or longer sent its 200 headers and then closed the connection: the buffer is sized for the longest path the server accepts, and anything longer is refused before the headers go out. - A URL path or query longer than the server keeps is refused with 414, instead of acting on the cut-off name. - Replies built with snprintf could send bytes past their stack buffer on long paths: the buffers are sized for two paths, and a reply never sends more than its text.
- An upload the server refuses before reading the body (409 exists, 503 busy, 404, 400, 413) used to end in a connection reset and exit 8, "cannot reach", with the reason lost. The CLI now reads the reply after a failed send and exits with the code for that status. Also for runner adv load. - A 200 whose body is not valid JSON printed "error (200)" and exited 0: it now exits 1. Bodies are decoded leniently, so a listing with a name in the Atari's character set (an umlaut) works. - gemdrive get -r on a file that is already complete printed a range error and exited 5: it now says the file is complete and exits 0, and refuses, without touching it, a local file larger than the remote one. - debug tail shows bytes as they arrive instead of in 256-byte blocks, so the end of a program's output is no longer held back. Nine new tests, 128 in all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent readings of the merged v1.2.0 code turned up a long list of findings, area by area. That list also includes a command-by-command check of what the ST sends against what the RP reads, and a comparison of GEMDRIVE with md-drives-emulator's. This PR fixes the ones that lose data, escape the GEMDRIVE folder or give programs a wrong answer, and that are small and can be proven without the device. The m68k-side and larger findings are left for review at the release gate.
Fixed
The GEMDRIVE folder is a real boundary again (two independent ways out of it):
Dsetpath("..")at the drive's root made the root of the card current. Relative paths are now normalised, with..stopping at the root (md-drives-emulator's normaliser).%5C..(a backslash) got past the path check, so a listing, PUT or DELETE could reach any file on the card.\now separates folders exactly like/.GEMDRIVE answers as TOS does:
Fsfirst("NAME.*")andFsfirst("C:*.BIN")find their files.No more lost data, or stray data:
UPLOAD~N.TMPand replaces the original only when complete.HTTP:
CLI:
get -ron a complete file succeeds.debug tailshows bytes as they arrive.Checked
GDTEST.TOSgains nine checks for the GEMDRIVE fixes. In EmuMD, all nine fail on the code before this branch, and on this branch all 16 checks pass on ST TOS 1.04, STE 1.62 and Mega STE 2.06.%5C..gets400 bad_path.put -freplaces it with no temporary file left behind.releaseanddebugbuild. BSS grows by about 640 bytes.Not fixed here
These go to the release gate:
[G]hang: an intermittent hang in 1 of 4 EmuMD runs.