aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2018-04-18 09:09:05 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-04-18 10:24:42 +0200
commiteb796b4bbb86fc488cf3d444f36e5f4a3120d959 (patch)
tree4003aeda3a6b67c9fd97eaaf5ec2e4553093d79b
parent87b8d232bd52ad7b89ecb361641427ec3dbdef38 (diff)
downloadlibssh-eb796b4bbb86fc488cf3d444f36e5f4a3120d959.tar.gz
libssh-eb796b4bbb86fc488cf3d444f36e5f4a3120d959.tar.xz
libssh-eb796b4bbb86fc488cf3d444f36e5f4a3120d959.zip
buffer: Do not call memcpy with null arguments
This allows compiling and testing with undefined sanitizer. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/buffer.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 205aa333..89fd0f6d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -145,9 +145,11 @@ static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
if (new == NULL) {
return -1;
}
- memcpy(new, buffer->data,buffer->used);
- explicit_bzero(buffer->data, buffer->used);
- SAFE_FREE(buffer->data);
+ if (buffer->used > 0) {
+ memcpy(new, buffer->data,buffer->used);
+ explicit_bzero(buffer->data, buffer->used);
+ SAFE_FREE(buffer->data);
+ }
} else {
new = realloc(buffer->data, needed);
if (new == NULL) {