zhhyu7 opened a new pull request, #4195:
URL: https://github.com/apache/nuttx-apps/pull/4195
## Summary
ftpd_command_port() built the data address with (value[0] << 24), where
value[] is uint8_t promoted to int, so an octet >= 128 shifted into the
sign bit (undefined behavior). Cast each octet to unsigned int first.
When an octet was out of range, the function sent "501 Illegal PORT
command" and then carried on and also sent "200 PORT command successful"
for the same command. Return right after the 501.
The second commit removes the "#if 1 / #else" block that used the
command socket's peer address instead of the PORT argument; it was never
built.
## Impact
- Active-mode FTP (PORT) only. Passive mode is unchanged.
- No Kconfig, API or build-system change.
## Testing
sim:dynconns + CONFIG_NETUTILS_FTPD + CONFIG_EXAMPLES_FTPD on the nuttx0
bridge. A Python client on the host logs in, sends an illegal PORT,
then opens an active-mode data connection on host port 50000
(PORT 10,0,1,1,195,80: the high byte is >= 128) and runs LIST.
This branch:
```
< 220 NuttX FTP Server
> USER root
< 331 Password required for root
> PASS abc123
< 230 Login successful.
> PORT 10,0,1,1,300,1
< 501 Illegal PORT command
extra replies after 501: b''
> NOOP
< 200 NOOP command successful
> PORT 10,0,1,1,195,80
< 200 PORT command successful
> LIST /
< 150 Opening ASCII mode data connection for file list
data from ('10.0.1.2', 28429), 301 bytes: b'dr-xr-xr-x 1 1001 512
0 Jan 1 1970 bin\r\ndr-xr-xr-x 1 1001 512 0 Jan 1
1970 dev\r\n'
< 226 Transfer complete
> QUIT
< 221 Good-bye
```
apache/master, same client (two runs; the stray 200 shows up in one of
them depending on timing):
```
> PORT 10,0,1,1,300,1
< 501 Illegal PORT command
extra replies after 501: b'200 PORT command successful\r\n'
```
checkpatch.sh -c -u -m -g passes for every commit.
--
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]