From: Anthony Liguori <anthony@codemonkey.ws>
To: Jim Meyering <jim@meyering.net>, qemu-devel@nongnu.org
Cc: Jim Meyering <meyering@redhat.com>
Subject: Re: [Qemu-devel] [PATCHv3 01/20] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL
Date: Fri, 05 Oct 2012 16:17:38 -0500 [thread overview]
Message-ID: <87lifkpqj1.fsf@codemonkey.ws> (raw)
In-Reply-To: <1349349003-15672-2-git-send-email-jim@meyering.net>
Jim Meyering <jim@meyering.net> writes:
> From: Jim Meyering <meyering@redhat.com>
>
> Use g_strdup rather than strdup, because the sole caller
> (qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences
> it. Besides, in that caller, the allocated buffer is already freed with
> g_free, so it's better to allocate with a matching g_strdup.
>
> In one case, (scsi-bus.c) it was trivial, so I replaced an snprintf+
> g_strdup combination with an equivalent g_strdup_printf use.
>
> Signed-off-by: Jim Meyering <meyering@redhat.com>
Applied all. Thanks.
Regards,
Anthony Liguori
> ---
> hw/ide/qdev.c | 2 +-
> hw/isa-bus.c | 2 +-
> hw/pci.c | 2 +-
> hw/qdev.c | 2 +-
> hw/scsi-bus.c | 8 ++------
> hw/sysbus.c | 2 +-
> 6 files changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
> index 5ea9b8f..f2e4ea4 100644
> --- a/hw/ide/qdev.c
> +++ b/hw/ide/qdev.c
> @@ -60,7 +60,7 @@ static char *idebus_get_fw_dev_path(DeviceState *dev)
> snprintf(path, sizeof(path), "%s@%d", qdev_fw_name(dev),
> ((IDEBus*)dev->parent_bus)->bus_id);
>
> - return strdup(path);
> + return g_strdup(path);
> }
>
> static int ide_qdev_init(DeviceState *qdev)
> diff --git a/hw/isa-bus.c b/hw/isa-bus.c
> index f9b2373..47c93d3 100644
> --- a/hw/isa-bus.c
> +++ b/hw/isa-bus.c
> @@ -236,7 +236,7 @@ static char *isabus_get_fw_dev_path(DeviceState *dev)
> snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id);
> }
>
> - return strdup(path);
> + return g_strdup(path);
> }
>
> MemoryRegion *isa_address_space(ISADevice *dev)
> diff --git a/hw/pci.c b/hw/pci.c
> index f855cf3..de4b448 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1962,7 +1962,7 @@ static char *pcibus_get_fw_dev_path(DeviceState *dev)
> PCI_SLOT(d->devfn));
> if (PCI_FUNC(d->devfn))
> snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
> - return strdup(path);
> + return g_strdup(path);
> }
>
> static char *pcibus_get_dev_path(DeviceState *dev)
> diff --git a/hw/qdev.c b/hw/qdev.c
> index b5a52ac..3b5ce33 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -520,7 +520,7 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
>
> path[l-1] = '\0';
>
> - return strdup(path);
> + return g_strdup(path);
> }
>
> char *qdev_get_dev_path(DeviceState *dev)
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index 058d3b2..dfb2631 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -1723,12 +1723,8 @@ static char *scsibus_get_dev_path(DeviceState *dev)
> static char *scsibus_get_fw_dev_path(DeviceState *dev)
> {
> SCSIDevice *d = SCSI_DEVICE(dev);
> - char path[100];
> -
> - snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel,
> - qdev_fw_name(dev), d->id, d->lun);
> -
> - return strdup(path);
> + return g_strdup_printf("channel@%x/%s@%x,%x", d->channel,
> + qdev_fw_name(dev), d->id, d->lun);
> }
>
> SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
> diff --git a/hw/sysbus.c b/hw/sysbus.c
> index 9d8b1ea..c173840 100644
> --- a/hw/sysbus.c
> +++ b/hw/sysbus.c
> @@ -211,7 +211,7 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev)
> snprintf(path + off, sizeof(path) - off, "@i%04x", s->pio[0]);
> }
>
> - return strdup(path);
> + return g_strdup(path);
> }
>
> void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
> --
> 1.8.0.rc0.18.gf84667d
next prev parent reply other threads:[~2012-10-05 21:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-04 11:09 [Qemu-devel] [PATCHv3 00/20] strncpy: best avoided Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 01/20] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL Jim Meyering
2012-10-05 21:17 ` Anthony Liguori [this message]
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 02/20] sparc: use g_strdup in place of unchecked strdup Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 03/20] block: avoid buffer overrun by using pstrcpy, not strncpy Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 04/20] sheepdog: avoid a few buffer overruns Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 05/20] vmdk: relative_path: use pstrcpy in place of strncpy Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 06/20] hw/9pfs: avoid buffer overrun Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 07/20] lm32: " Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 08/20] os-posix: " Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 09/20] ppc: avoid buffer overrun: use pstrcpy, not strncpy Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 10/20] linux-user: remove two unchecked uses of strdup Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 11/20] ui/vnc: simplify and avoid strncpy Jim Meyering
2012-10-04 18:48 ` Peter Maydell
2012-10-04 18:56 ` Jim Meyering
2012-10-04 19:02 ` Peter Maydell
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 12/20] bt: replace fragile snprintf use and unwarranted strncpy Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 13/20] virtio-9p: avoid unwarranted uses of strncpy Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 14/20] vscsi: avoid unwarranted strncpy Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 15/20] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name Jim Meyering
2012-10-04 11:09 ` [Qemu-devel] [PATCHv3 16/20] libcacard/vcard_emul_nss: use pstrcpy in place of strncpy Jim Meyering
2012-10-04 11:10 ` [Qemu-devel] [PATCHv3 17/20] acpi: remove strzcpy (strncpy-identical) function; just use strncpy Jim Meyering
2012-10-04 11:10 ` [Qemu-devel] [PATCHv3 18/20] qcow2: mark this file's sole strncpy use as justified Jim Meyering
2012-10-04 11:10 ` [Qemu-devel] [PATCHv3 19/20] hw/r2d: add comment: this strncpy use is ok Jim Meyering
2012-10-04 11:10 ` [Qemu-devel] [PATCHv3 20/20] doc: update HACKING wrt strncpy/pstrcpy Jim Meyering
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lifkpqj1.fsf@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=jim@meyering.net \
--cc=meyering@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.