Skip to content

Skip the blank line some servers end an MLSD listing with - #77

Open
christhomas wants to merge 1 commit into
secsy:masterfrom
antimatter-studios:cth/mlsd-blank-upstream
Open

Skip the blank line some servers end an MLSD listing with#77
christhomas wants to merge 1 commit into
secsy:masterfrom
antimatter-studios:cth/mlsd-blank-upstream

Conversation

@christhomas

Copy link
Copy Markdown

Fixes #45.

A trailing empty line is not an entry, and parsing it as one fails the whole listing — so a directory that is perfectly readable comes back as:

failed parsing MLST entry:

with nothing after the colon, which is what makes it hard to place.

parseLIST already skips its own non-entry line (total 404456), so the two parsers now agree that a line which is not an entry is not an error either. Whitespace-only lines count, since a server sending \r is sending the same nothing.

A second-order effect worth pointing out

Stat shares this parser and expects the single line it passes in to be the answer. Reporting "not an entry" as (nil, nil) is right for a listing and wrong there: Stat would return a nil os.FileInfo with a nil error, and a caller that checked the error would then dereference nothing.

So Stat now rejects an MLST reply whose entry line is blank. I confirmed that red first — both test servers returned a nil FileInfo and no error before the guard went in.

The malformed case is still an error, so skipping blank lines has not become skipping anything inconvenient. There is a test for that.

@olegabr's suggestion in the issue was exactly this; @tommed also has a fix in a fork.

One note on running the tests: this branch is off master, so TestMain still requires ./build_test_server.sh — the tests here need no server, but they cannot start without one. I verified them via the container harness in #73.

Fixes secsy#45.

A trailing empty line is not an entry, and parsing it as one failed the
whole listing — so a directory that was perfectly readable came back as
"failed parsing MLST entry:" with nothing after the colon.

parseLIST already skips its own non-entry line ("total 404456"), so the
two parsers now agree that a line which is not an entry is not an error
either. Whitespace-only lines count, since a server sending "\\r" is
sending the same nothing.

## A second-order effect, which the fix would otherwise have introduced

Stat shares the parser and expects the one line it passes in to be the
answer. Reporting "not an entry" as (nil, nil) is right for a listing and
wrong there: Stat would have returned a nil FileInfo with a nil error,
and a caller that checked the error would then dereference nothing.

Stat now rejects an MLST reply whose entry line is blank. That was
confirmed red — both test servers returned a nil FileInfo and no error
before the guard.

The malformed case is still an error, so skipping blank lines has not
become skipping anything inconvenient; there is a test for that.
@christhomas christhomas mentioned this pull request Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed parsing MLSD response on some servers

1 participant