Croway commented on PR #30211:
URL: https://github.com/apache/camel/pull/30211#issuecomment-6920079459
The CR/LF check covers every `FtpOperations` method that sends a name, and
`FtpProducerFileNameLineBreakTest` passes here. I found three gaps, each
reproduced on the PR head (`af1b9127`) with `FakeFtpServer` and a control case
in the same test class.
**1. A NUL in the name is still sent**
`checkName` (`FtpOperations.java:1122`) refuses only `\r` and `\n`. With
`CamelFileName = "existing.txt\u0000.part"`, the exchange succeeds and the
server receives:
```
... PASV, STOR existing.txt\0.part, CWD /
```
Control: `"existing.txt\n.part"` is refused. A server that passes the
argument to a C file API stops at the NUL and writes `existing.txt`, which is
the "acted on another file" case this PR is about.
`ScpOperations.checkFileName` (camel-jsch, line 537), the model this PR
follows, refuses `\0` for this reason. I suggest refusing `'\0'` here too, and
naming it in the docs and the upgrade guides.
**2. With a fixed `tempFileName`, the body is uploaded before the name is
refused, and the temp file stays on the server**
With `fileExist=TryRename` or `eagerDeleteTargetFile=false`
(`GenericFileProducer.java:153` and `:188`), the producer writes the temp file
(`:182`) before it uses the target name. The first `checkName` on the target
name is then in `renameFile` (`:202`). With
`fileExist=TryRename&tempFileName=inprogress.tmp` and `CamelFileName =
"before\nafter.txt"`, the exchange is refused, but only after:
```
USER camel, PASS secret, TYPE A, PWD, CWD outbox, CWD /, PWD, CWD outbox,
PASV, STOR inprogress.tmp, CWD /, QUIT
files on the server: /outbox/inprogress.tmp (the full body),
/outbox/existing.txt
```
The same happens with
`eagerDeleteTargetFile=false&tempFileName=inprogress.tmp`. Control: with
`tempFileName=${file:name}.tmp`, the exchange is refused and no `STOR` is sent.
Every temp name in `fileNameWithLineBreakIsRefusedWithOption` is derived from
the target name, so the test never reaches this path.
**3. Commands are still sent before the refusal, and `autoCreate` creates
the parent directory**
The docs say the name is refused "before they send any command to the server
for it" (`ftp-component.adoc:275`, `camel-4x-upgrade-guide-4_24.adoc:419`,
`4_22.adoc:120`, `4_18.adoc:99`, and the `checkName` javadoc). In fact the
producer connects, logs in and builds the parent directory first. With
`CamelFileName = "sub/before\nafter.txt"`:
```
USER camel, PASS secret, TYPE A, PWD, CWD outbox/sub, MKD outbox/sub, CWD /,
QUIT
```
So the refused exchange leaves an empty `outbox/sub` directory. Control:
`"before\nafter.txt"` sends no `MKD`. The PR's test checks `server.files()` and
that no command contains the name, so it does not catch this.
Points 2 and 3 share one fix: check the target name, and the temp name, once
in the producer before `preWriteCheck`/`writeFile`, and keep the per-operation
check as a backstop. If that is out of scope for this PR, the docs could say
instead that the name is refused before any command carrying the name is sent.
Point 2 would still need a fix.
_Claude Code on behalf of Croway_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]