ftp: use int for sent to preserve SSL_write() - #19912
Conversation
|
Could probably be |
|
I chose this approach for easier backporting to PHP 8.3 (which supports OpenSSL ≥ 1.0.2 and is my primary focus). Since
I can rework the PR if you prefer that variant for master. |
db286fe to
269f975
Compare
Thanks for the review. I’ve pushed a new version. |
|
OpenSSL 1.1.1 is minimum since 8.4 so you can use SSL_write_ex if you target 8.4+ which should be fine for this. Not sure if we should even treat it as a bug but I'm fine either way. |
Replace SSL_write() with SSL_write_ex() and pass its return value to SSL_get_error(). This preserves the original API contract and avoids signed/unsigned conversion issues when handling errors. Signed-off-by: Denis Sergeev <zeff@altlinux.org>
269f975 to
87653e2
Compare
|
Got it, updated to use |
|
This is already better. |
What is fixed
SSL_write()returnsintand uses negative values to indicate errors.The variable
sentinext/ftp/ftp.cwas declared assize_t, whichcaused negative return values to be converted into large positive numbers.
Why it matters
Although this value is later passed to
SSL_get_error(), the OpenSSL APIrequires the original return value of
SSL_write()to be used. Passing aconverted unsigned value may lead to incorrect error handling and potentially
report a failed write as a success.
Why change is safe
While the implicit int → size_t → int conversion is “usually” safe on most
compilers, it relies on implementation-defined behavior. Using a signed
intmakes the code clearer, avoids subtle portability issues, and directly matches
the return type contract of
SSL_write().How it is fixed
Changed the type of
sentfromsize_ttoint.