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:
@@ -817,6 +817,7 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(str_len) {
|
||||
*outbuf = LIBSSH2_ALLOC(session, str_len);
|
||||
if(*outbuf) {
|
||||
memcpy(*outbuf, str, str_len);
|
||||
@@ -824,6 +825,11 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*outlen = 0;
|
||||
*outbuf = NULL;
|
||||
}
|
||||
|
||||
if(outlen)
|
||||
*outlen = str_len;
|
||||
|
||||
Reference in New Issue
Block a user