mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +03:00
misc/libssh2_copy_string: avoid malloc zero bytes
Avoids the inconsistent malloc return code for malloc(0) Closes #686
This commit is contained in:
14
src/misc.c
14
src/misc.c
@@ -817,12 +817,18 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
return -1;
|
||||
}
|
||||
|
||||
*outbuf = LIBSSH2_ALLOC(session, str_len);
|
||||
if(*outbuf) {
|
||||
memcpy(*outbuf, str, str_len);
|
||||
if(str_len) {
|
||||
*outbuf = LIBSSH2_ALLOC(session, str_len);
|
||||
if(*outbuf) {
|
||||
memcpy(*outbuf, str, str_len);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
*outlen = 0;
|
||||
*outbuf = NULL;
|
||||
}
|
||||
|
||||
if(outlen)
|
||||
|
||||
Reference in New Issue
Block a user