Bug 2187717

Summary: Cannot upload files to Jscape SFTP server: file gets created empty
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: curlAssignee: Jacek Migacz <jmigacz>
Status: VERIFIED --- QA Contact: Daniel Rusek <drusek>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 8.7CC: cbesson, fkrska, jamacku, kdudka, mmatsuya, qguo
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: curl-7.61.1-33.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2188029 2188030 2188031 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2188029, 2188030, 2188031    

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