forked from pool/libssh2_org
- open library file descriptors with O_CLOEXEC OBS-URL: https://build.opensuse.org/request/show/94640 OBS-URL: https://build.opensuse.org/package/show/devel:libraries:c_c++/libssh2_org?expand=0&rev=34
62 lines
2.3 KiB
Diff
62 lines
2.3 KiB
Diff
diff --git a/src/agent.c b/src/agent.c
|
|
index 5a9e81c..989b7ec 100644
|
|
--- a/src/agent.c
|
|
+++ b/src/agent.c
|
|
@@ -152,7 +152,7 @@ agent_connect_unix(LIBSSH2_AGENT *agent)
|
|
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
|
|
"no auth sock variable");
|
|
|
|
- agent->fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
|
+ agent->fd = socket(PF_UNIX, SOCK_STREAM| SOCK_CLOEXEC, 0);
|
|
if (agent->fd < 0)
|
|
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_SOCKET,
|
|
"failed creating socket");
|
|
diff --git a/src/knownhost.c b/src/knownhost.c
|
|
index d90f1d4..8862c58 100644
|
|
--- a/src/knownhost.c
|
|
+++ b/src/knownhost.c
|
|
@@ -905,7 +905,7 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
|
|
"Unsupported type of known-host information "
|
|
"store");
|
|
|
|
- file = fopen(filename, "r");
|
|
+ file = fopen(filename, "re");
|
|
if(file) {
|
|
while(fgets(buf, sizeof(buf), file)) {
|
|
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type))
|
|
@@ -1077,7 +1077,7 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
|
|
"Unsupported type of known-host information "
|
|
"store");
|
|
|
|
- file = fopen(filename, "w");
|
|
+ file = fopen(filename, "we");
|
|
if(!file)
|
|
return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
|
|
"Failed to open file");
|
|
diff --git a/src/userauth.c b/src/userauth.c
|
|
index d74c0c8..7e8efb6 100644
|
|
--- a/src/userauth.c
|
|
+++ b/src/userauth.c
|
|
@@ -467,7 +467,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
|
_libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s",
|
|
pubkeyfile);
|
|
/* Read Public Key */
|
|
- fd = fopen(pubkeyfile, "r");
|
|
+ fd = fopen(pubkeyfile, "re");
|
|
if (!fd) {
|
|
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
|
"Unable to open public key file");
|
|
diff --git a/tests/ssh2.c b/tests/ssh2.c
|
|
index e09ba8a..9469970 100644
|
|
--- a/tests/ssh2.c
|
|
+++ b/tests/ssh2.c
|
|
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
|
|
|
|
hostaddr = htonl(0x7F000001);
|
|
|
|
- sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
+ sock = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
|
#ifndef WIN32
|
|
fcntl(sock, F_SETFL, 0);
|
|
#endif
|