qed: don't pass NULL to memcpy
PATCH 1/1 qed: don't pass NULL to memcpy
Spotted by Clang Analyzer
--- block/qed.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
block/qed.c +4 -2
@@ -1424,8 +1424,10 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs,memcpy (buffer, &le_header,sizeof (le_header)); buffer_len =sizeof (le_header); -memcpy (buffer + buffer_len, backing_file, backing_file_len); - buffer_len += backing_file_len; +if (backing_file) { +memcpy (buffer + buffer_len, backing_file, backing_file_len); + buffer_len += backing_file_len; + }/* Write new header */ ret =bdrv_pwrite_sync (bs->file,0 , buffer, buffer_len);
Signature · 1 line
1.7.0.4
Stefan Hajnoczi
AppliedQuoted 6 lines · Pavel Borzenkov
Spotted by Clang Analyzer
Signed-off-by Pavel Borzenkov <[email protected]>--- block/qed.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches
Stefan
Quoted 10 lines · Stefan Hajnoczi
Quoted 6 lines · Pavel Borzenkov
Spotted by Clang Analyzer
Signed-off-by Pavel Borzenkov<[email protected]>--- block/qed.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches
I think there are other places in the tree where we assume that "memcpy(dest, NULL, 0);" works.
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Stefan Hajnoczi
Quoted 6 lines · Pavel Borzenkov
Spotted by Clang Analyzer
Signed-off-by Pavel Borzenkov<[email protected]>--- block/qed.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 2 lines
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patchesI think there are other places in the tree where we assume that "
memcpy(dest, NULL, 0);" works.
Looks like a fair assumption to me.
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Stefan Hajnoczi
Quoted 6 lines · Pavel Borzenkov
Spotted by Clang Analyzer
Signed-off-by Pavel Borzenkov<[email protected]>--- block/qed.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patchesI think there are other places in the tree where we assume that "
memcpy(dest, NULL, 0);" works.Looks like a fair assumption to me.
Such calls work, but this is UB. Calling string functions with NULL pointers and zero length is a violation of the C99 standard:
7.21.1 String function conventions
Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4.
Signature · 1 line
Pavel
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Stefan Hajnoczi
Quoted 6 lines · Pavel Borzenkov
Spotted by Clang Analyzer
Signed-off-by Pavel Borzenkov<[email protected]>---
block/qed.c| 6 ++++--1 files changed, 4 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patchesI think there are other places in the tree where we assume that "
memcpy(dest, NULL, 0);" works.Looks like a fair assumption to me.
Such calls work, but this is UB. Calling string functions with NULL pointers and zero length is a violation of the C99 standard:
7.21.1 String function conventions
Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4.
Signature · 1 line
Pavel