* [Qemu-devel] [PATCH] qed: don't pass NULL to memcpy
@ 2011-10-18 17:17 Pavel Borzenkov
2011-10-20 17:23 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
0 siblings, 1 reply; 6+ messages in thread
From: Pavel Borzenkov @ 2011-10-18 17:17 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Spotted by Clang Analyzer
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
---
block/qed.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index c3e45af..e6720db 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -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);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] qed: don't pass NULL to memcpy
2011-10-18 17:17 [Qemu-devel] [PATCH] qed: don't pass NULL to memcpy Pavel Borzenkov
@ 2011-10-20 17:23 ` Stefan Hajnoczi
2011-10-21 6:35 ` Paolo Bonzini
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2011-10-20 17:23 UTC (permalink / raw)
To: Pavel Borzenkov; +Cc: qemu-trivial, qemu-devel
On Tue, Oct 18, 2011 at 09:17:35PM +0400, Pavel Borzenkov wrote:
> Spotted by Clang Analyzer
>
> Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
> ---
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] qed: don't pass NULL to memcpy
2011-10-20 17:23 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
@ 2011-10-21 6:35 ` Paolo Bonzini
2011-10-21 8:31 ` Markus Armbruster
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2011-10-21 6:35 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-trivial, qemu-devel, Pavel Borzenkov
On 10/20/2011 07:23 PM, Stefan Hajnoczi wrote:
> On Tue, Oct 18, 2011 at 09:17:35PM +0400, Pavel Borzenkov wrote:
>> Spotted by Clang Analyzer
>>
>> Signed-off-by: Pavel Borzenkov<pavel.borzenkov@gmail.com>
>> ---
>> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] qed: don't pass NULL to memcpy
2011-10-21 6:35 ` Paolo Bonzini
@ 2011-10-21 8:31 ` Markus Armbruster
2011-10-21 9:06 ` Pavel Borzenkov
2011-10-21 9:08 ` Pavel Borzenkov
0 siblings, 2 replies; 6+ messages in thread
From: Markus Armbruster @ 2011-10-21 8:31 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-trivial, Stefan Hajnoczi, qemu-devel, Pavel Borzenkov
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 10/20/2011 07:23 PM, Stefan Hajnoczi wrote:
>> On Tue, Oct 18, 2011 at 09:17:35PM +0400, Pavel Borzenkov wrote:
>>> Spotted by Clang Analyzer
>>>
>>> Signed-off-by: Pavel Borzenkov<pavel.borzenkov@gmail.com>
>>> ---
>>> 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.
Looks like a fair assumption to me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] qed: don't pass NULL to memcpy
2011-10-21 8:31 ` Markus Armbruster
@ 2011-10-21 9:06 ` Pavel Borzenkov
2011-10-21 9:08 ` Pavel Borzenkov
1 sibling, 0 replies; 6+ messages in thread
From: Pavel Borzenkov @ 2011-10-21 9:06 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-trivial, Paolo Bonzini, qemu-devel, Stefan Hajnoczi
On 10/21/2011 12:31 PM, Markus Armbruster wrote:
> Paolo Bonzini<pbonzini@redhat.com> writes:
>
>> On 10/20/2011 07:23 PM, Stefan Hajnoczi wrote:
>>> On Tue, Oct 18, 2011 at 09:17:35PM +0400, Pavel Borzenkov wrote:
>>>> Spotted by Clang Analyzer
>>>>
>>>> Signed-off-by: Pavel Borzenkov<pavel.borzenkov@gmail.com>
>>>> ---
>>>> 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.
>
> 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.
--
Pavel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] qed: don't pass NULL to memcpy
2011-10-21 8:31 ` Markus Armbruster
2011-10-21 9:06 ` Pavel Borzenkov
@ 2011-10-21 9:08 ` Pavel Borzenkov
1 sibling, 0 replies; 6+ messages in thread
From: Pavel Borzenkov @ 2011-10-21 9:08 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-trivial, Paolo Bonzini, qemu-devel, Stefan Hajnoczi
On Fri, Oct 21, 2011 at 12:31 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
>> On 10/20/2011 07:23 PM, Stefan Hajnoczi wrote:
>>> On Tue, Oct 18, 2011 at 09:17:35PM +0400, Pavel Borzenkov wrote:
>>>> Spotted by Clang Analyzer
>>>>
>>>> Signed-off-by: Pavel Borzenkov<pavel.borzenkov@gmail.com>
>>>> ---
>>>> 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.
>
> 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.
--
Pavel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-10-21 9:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-18 17:17 [Qemu-devel] [PATCH] qed: don't pass NULL to memcpy Pavel Borzenkov
2011-10-20 17:23 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2011-10-21 6:35 ` Paolo Bonzini
2011-10-21 8:31 ` Markus Armbruster
2011-10-21 9:06 ` Pavel Borzenkov
2011-10-21 9:08 ` Pavel Borzenkov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.