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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*outbuf = LIBSSH2_ALLOC(session, str_len);
|
if(str_len) {
|
||||||
if(*outbuf) {
|
*outbuf = LIBSSH2_ALLOC(session, str_len);
|
||||||
memcpy(*outbuf, str, str_len);
|
if(*outbuf) {
|
||||||
|
memcpy(*outbuf, str, str_len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
*outlen = 0;
|
||||||
|
*outbuf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(outlen)
|
if(outlen)
|
||||||
|
|||||||
Reference in New Issue
Block a user