mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-21 14:00:51 +03:00
src: address fopen() warnings, add missing copyright headers
Ref: https://github.com/libssh2/libssh2/pull/235
This commit is contained in:
@@ -955,7 +955,7 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
|
|||||||
"Unsupported type of known-host information "
|
"Unsupported type of known-host information "
|
||||||
"store");
|
"store");
|
||||||
|
|
||||||
file = fopen(filename, "r");
|
file = fopen(filename, FOPEN_READTEXT);
|
||||||
if(file) {
|
if(file) {
|
||||||
while(fgets(buf, sizeof(buf), file)) {
|
while(fgets(buf, sizeof(buf), file)) {
|
||||||
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) {
|
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) {
|
||||||
@@ -1179,7 +1179,7 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
|
|||||||
"Unsupported type of known-host information "
|
"Unsupported type of known-host information "
|
||||||
"store");
|
"store");
|
||||||
|
|
||||||
file = fopen(filename, "w");
|
file = fopen(filename, FOPEN_WRITETEXT);
|
||||||
if(!file)
|
if(!file)
|
||||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
|
return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
|
||||||
"Failed to open file");
|
"Failed to open file");
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
|||||||
unsigned char *n, *e, *d, *p, *q, *e1, *e2, *coeff;
|
unsigned char *n, *e, *d, *p, *q, *e1, *e2, *coeff;
|
||||||
unsigned int nlen, elen, dlen, plen, qlen, e1len, e2len, coefflen;
|
unsigned int nlen, elen, dlen, plen, qlen, e1len, e2len, coefflen;
|
||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, FOPEN_READTEXT);
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
|||||||
unsigned char *p, *q, *g, *y, *x;
|
unsigned char *p, *q, *g, *y, *x;
|
||||||
unsigned int plen, qlen, glen, ylen, xlen;
|
unsigned int plen, qlen, glen, ylen, xlen;
|
||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, FOPEN_READTEXT);
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1076,4 +1076,27 @@ void _libssh2_init_if_needed(void);
|
|||||||
#define LIBSSH2_INT64_T_FORMAT "lld"
|
#define LIBSSH2_INT64_T_FORMAT "lld"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* In Windows the default file mode is text but an application can override it.
|
||||||
|
Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
|
||||||
|
*/
|
||||||
|
#if defined(WIN32) || defined(MSDOS)
|
||||||
|
#define FOPEN_READTEXT "rt"
|
||||||
|
#define FOPEN_WRITETEXT "wt"
|
||||||
|
#define FOPEN_APPENDTEXT "at"
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
/* Cygwin has specific behavior we need to address when WIN32 is not defined.
|
||||||
|
https://cygwin.com/cygwin-ug-net/using-textbinary.html
|
||||||
|
For write we want our output to have line endings of LF and be compatible with
|
||||||
|
other Cygwin utilities. For read we want to handle input that may have line
|
||||||
|
endings either CRLF or LF so 't' is appropriate.
|
||||||
|
*/
|
||||||
|
#define FOPEN_READTEXT "rt"
|
||||||
|
#define FOPEN_WRITETEXT "w"
|
||||||
|
#define FOPEN_APPENDTEXT "a"
|
||||||
|
#else
|
||||||
|
#define FOPEN_READTEXT "r"
|
||||||
|
#define FOPEN_WRITETEXT "w"
|
||||||
|
#define FOPEN_APPENDTEXT "a"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* LIBSSH2_H */
|
#endif /* LIBSSH2_H */
|
||||||
|
|||||||
@@ -1,3 +1,40 @@
|
|||||||
|
/* Copyright (c) 2016, Art <https://github.com/wildart>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms,
|
||||||
|
* with or without modification, are permitted provided
|
||||||
|
* that the following conditions are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
* copyright notice, this list of conditions and the
|
||||||
|
* following disclaimer.
|
||||||
|
*
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following
|
||||||
|
* disclaimer in the documentation and/or other materials
|
||||||
|
* provided with the distribution.
|
||||||
|
*
|
||||||
|
* Neither the name of the copyright holder nor the names
|
||||||
|
* of any other contributors may be used to endorse or
|
||||||
|
* promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||||
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "libssh2_priv.h"
|
#include "libssh2_priv.h"
|
||||||
|
|
||||||
#ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */
|
#ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */
|
||||||
|
|||||||
@@ -1,3 +1,40 @@
|
|||||||
|
/* Copyright (c) 2016, Art <https://github.com/wildart>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms,
|
||||||
|
* with or without modification, are permitted provided
|
||||||
|
* that the following conditions are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
* copyright notice, this list of conditions and the
|
||||||
|
* following disclaimer.
|
||||||
|
*
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following
|
||||||
|
* disclaimer in the documentation and/or other materials
|
||||||
|
* provided with the distribution.
|
||||||
|
*
|
||||||
|
* Neither the name of the copyright holder nor the names
|
||||||
|
* of any other contributors may be used to endorse or
|
||||||
|
* promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||||
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
@@ -543,7 +543,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
|||||||
_libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s",
|
_libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s",
|
||||||
pubkeyfile);
|
pubkeyfile);
|
||||||
/* Read Public Key */
|
/* Read Public Key */
|
||||||
fd = fopen(pubkeyfile, "r");
|
fd = fopen(pubkeyfile, FOPEN_READTEXT);
|
||||||
if(!fd) {
|
if(!fd) {
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||||
"Unable to open public key file");
|
"Unable to open public key file");
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ _libssh2_wincng_load_pem(LIBSSH2_SESSION *session,
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, FOPEN_READTEXT);
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user