* [Qemu-devel] [PATCH 1/1] block/sheepdog: fix argument passed to qemu_strtoul()
@ 2016-03-02 15:16 Jeff Cody
2016-03-02 15:27 ` [Qemu-devel] [Qemu-block] " Max Reitz
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Cody @ 2016-03-02 15:16 UTC (permalink / raw)
To: qemu-block
Cc: kwolf, mitake.hitoshi, qemu-devel, v.tolstov, pbonzini,
namei.unix
The function qemu_strtoul() reads 'unsigned long' sized data,
which is larger than uint32_t on 64-bit machines.
Even though the snap_id field in the header is 32-bits, we must
accomodate the full size in qemu_strtoul().
Reported-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
block/sheepdog.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 8739acc..c6bf900 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
const char *name,
Error **errp)
{
- uint32_t snap_id = 0;
+ unsigned long snap_id = 0;
char snap_tag[SD_MAX_VDI_TAG_LEN];
Error *local_err = NULL;
int fd, ret;
@@ -2565,12 +2565,12 @@ static int sd_snapshot_delete(BlockDriverState *bs,
memset(buf, 0, sizeof(buf));
memset(snap_tag, 0, sizeof(snap_tag));
pstrcpy(buf, SD_MAX_VDI_LEN, s->name);
- if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) {
+ if (qemu_strtoul(snapshot_id, NULL, 10, &snap_id)) {
return -1;
}
if (snap_id) {
- hdr.snapid = snap_id;
+ hdr.snapid = (uint32_t) snap_id;
} else {
pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);
pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 1/1] block/sheepdog: fix argument passed to qemu_strtoul()
2016-03-02 15:16 [Qemu-devel] [PATCH 1/1] block/sheepdog: fix argument passed to qemu_strtoul() Jeff Cody
@ 2016-03-02 15:27 ` Max Reitz
2016-03-02 15:38 ` Jeff Cody
0 siblings, 1 reply; 3+ messages in thread
From: Max Reitz @ 2016-03-02 15:27 UTC (permalink / raw)
To: Jeff Cody, qemu-block
Cc: kwolf, mitake.hitoshi, qemu-devel, v.tolstov, pbonzini,
namei.unix
[-- Attachment #1.1: Type: text/plain, Size: 1661 bytes --]
On 02.03.2016 16:16, Jeff Cody wrote:
> The function qemu_strtoul() reads 'unsigned long' sized data,
> which is larger than uint32_t on 64-bit machines.
>
> Even though the snap_id field in the header is 32-bits, we must
> accomodate the full size in qemu_strtoul().
>
> Reported-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
> block/sheepdog.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 8739acc..c6bf900 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> const char *name,
> Error **errp)
> {
> - uint32_t snap_id = 0;
> + unsigned long snap_id = 0;
> char snap_tag[SD_MAX_VDI_TAG_LEN];
> Error *local_err = NULL;
> int fd, ret;
> @@ -2565,12 +2565,12 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> memset(buf, 0, sizeof(buf));
> memset(snap_tag, 0, sizeof(snap_tag));
> pstrcpy(buf, SD_MAX_VDI_LEN, s->name);
> - if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) {
> + if (qemu_strtoul(snapshot_id, NULL, 10, &snap_id)) {
> return -1;
> }
>
> if (snap_id) {
> - hdr.snapid = snap_id;
> + hdr.snapid = (uint32_t) snap_id;
Maybe we should do an overflow check before?
Max
> } else {
> pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);
> pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 1/1] block/sheepdog: fix argument passed to qemu_strtoul()
2016-03-02 15:27 ` [Qemu-devel] [Qemu-block] " Max Reitz
@ 2016-03-02 15:38 ` Jeff Cody
0 siblings, 0 replies; 3+ messages in thread
From: Jeff Cody @ 2016-03-02 15:38 UTC (permalink / raw)
To: Max Reitz
Cc: kwolf, qemu-block, mitake.hitoshi, qemu-devel, v.tolstov,
namei.unix, pbonzini
On Wed, Mar 02, 2016 at 04:27:31PM +0100, Max Reitz wrote:
> On 02.03.2016 16:16, Jeff Cody wrote:
> > The function qemu_strtoul() reads 'unsigned long' sized data,
> > which is larger than uint32_t on 64-bit machines.
> >
> > Even though the snap_id field in the header is 32-bits, we must
> > accomodate the full size in qemu_strtoul().
> >
> > Reported-by: Paolo Bonzini <pbonzini@redhat.com>
> > Signed-off-by: Jeff Cody <jcody@redhat.com>
> > ---
> > block/sheepdog.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/block/sheepdog.c b/block/sheepdog.c
> > index 8739acc..c6bf900 100644
> > --- a/block/sheepdog.c
> > +++ b/block/sheepdog.c
> > @@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> > const char *name,
> > Error **errp)
> > {
> > - uint32_t snap_id = 0;
> > + unsigned long snap_id = 0;
> > char snap_tag[SD_MAX_VDI_TAG_LEN];
> > Error *local_err = NULL;
> > int fd, ret;
> > @@ -2565,12 +2565,12 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> > memset(buf, 0, sizeof(buf));
> > memset(snap_tag, 0, sizeof(snap_tag));
> > pstrcpy(buf, SD_MAX_VDI_LEN, s->name);
> > - if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) {
> > + if (qemu_strtoul(snapshot_id, NULL, 10, &snap_id)) {
> > return -1;
> > }
> >
> > if (snap_id) {
> > - hdr.snapid = snap_id;
> > + hdr.snapid = (uint32_t) snap_id;
>
> Maybe we should do an overflow check before?
>
Probably not a bad idea - easy enough, and that would prevent a false
positive match due to id truncation. I'll spin a v2.
Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-02 15:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-02 15:16 [Qemu-devel] [PATCH 1/1] block/sheepdog: fix argument passed to qemu_strtoul() Jeff Cody
2016-03-02 15:27 ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-03-02 15:38 ` Jeff Cody
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).