Bug 2187717 - Cannot upload files to Jscape SFTP server: file gets created empty
Summary: Cannot upload files to Jscape SFTP server: file gets created empty
Keywords:
Status: VERIFIED
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: curl
Version: 8.7
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: Jacek Migacz
QA Contact: Daniel Rusek
URL:
Whiteboard:
: 2186138 (view as bug list)
Depends On:
Blocks: 2188029 2188030 2188031
TreeView+ depends on / blocked
 
Reported: 2023-04-18 14:05 UTC by Renaud Métrich
Modified: 2023-07-31 18:15 UTC (History)
6 users (show)

Fixed In Version: curl-7.61.1-33.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2188029 2188030 2188031 (view as bug list)
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-155052 0 None None None 2023-04-18 14:27:06 UTC
Red Hat Issue Tracker RHELPLAN-155053 0 None None None 2023-04-18 14:27:08 UTC

Description Renaud Métrich 2023-04-18 14:05:54 UTC
Description of problem:

We have a customer reporting a bug with curl on RHEL 8.7.0: any transfer to their Jscape SFTP server creates the file but empty, the content is not copied.

RHEL 9.1.0 curl works fine.

Digging into this, it appears that there is a bug when setting the flags:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
 546 static CURLcode myssh_statemach_act(struct connectdata *conn, bool *block)
 547 {
 :
1114         /* Clear file before writing (normal behaviour) */
1115         flags = O_WRONLY|O_APPEND|O_CREAT|O_TRUNC;
 :
1119       sshc->sftp_file =
1120         sftp_open(sshc->sftp_session, protop->path,
1121                   flags, (mode_t)data->set.new_file_perms);
1122       if(!sshc->sftp_file) {
1123         err = sftp_get_error(sshc->sftp_session);
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

The flags state to O_APPEND + O_TRUNC, which is considered as an error on the Jscape SFTP server side.

This makes libssh fail to return a handle on line 1119 and "err" to be set to 4 ("Generic Error").

RHEL9 code is fixed, the flags line doesn't have O_APPEND anymore:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
1237         flags = O_WRONLY|O_CREAT|O_TRUNC;
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------


Version-Release number of selected component (if applicable):

libcurl-7.61.1-25.el8_7.3.x86_64

How reproducible:

Always when connection to customer system

Comment 1 Renaud Métrich 2023-04-18 14:07:21 UTC
I could confirm that live-patching curl fixes the issue:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# stap -v -g -e 'probe process("/usr/lib64/libcurl.so.4.5.0").statement("myssh_statemach_act@../../lib/ssh-libssh.c:1117") { if ($flags == 1601) $flags = 577 }'
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Comment 2 Kamil Dudka 2023-04-18 14:12:38 UTC
Thank you for debugging it, Renaud!

Backport of the upstream patch in question was already requested in bug #2186138 last week.

Comment 5 Kamil Dudka 2023-04-19 11:28:33 UTC
*** Bug 2186138 has been marked as a duplicate of this bug. ***

Comment 8 Kamil Dudka 2023-04-20 07:52:47 UTC
CentOS Stream merge request:
https://gitlab.com/redhat/centos-stream/rpms/curl/-/merge_requests/29


Note You need to log in before you can comment on or make changes to this bug.