[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interfa
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib |
Date: |
Thu, 8 Aug 2019 11:09:03 +0100 |
User-agent: |
Mutt/1.12.0 (2019-05-25) |
On Wed, Aug 07, 2019 at 12:44:40PM +0530, Balamuruhan S wrote:
> +void python_args_init_cast_int(char *args[], int arg, int pos)
> +{
> + args[pos]= malloc(sizeof(int));
> + sprintf(args[pos], "%d", arg);
> +}
This is broken. args[pos] is a (possibly NULL) pointer to 4 bytes.
sprintf() will buffer overflow if arg has more than 3 digits.
A correct way to do this is:
args[pos] = g_strdup_printf("%d", arg);
> +void python_args_init_cast_long(char *args[], uint64_t arg, int pos)
> +{
> + args[pos]= g_malloc(sizeof(uint64_t) * 2);
> + sprintf(args[pos], "%lx", arg);
> +}
Same issue.
> +void python_args_clean(char *args[], int nargs)
> +{
> + for (int i = 0; i < nargs; i++) {
> + g_free(args[i]);
> + }
> +}
Mixing malloc() and g_free() is unsafe. If you switch to
g_strdup_printf() then g_free() is correct.
signature.asc
Description: PGP signature
- [Qemu-devel] [RFC PATCH 0/6] Enhancing Qemu MMIO emulation with scripting interface, Balamuruhan S, 2019/08/07
- [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Balamuruhan S, 2019/08/07
- Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Philippe Mathieu-Daudé, 2019/08/07
- Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Stefan Hajnoczi, 2019/08/08
- Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Philippe Mathieu-Daudé, 2019/08/08
- Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Daniel P . Berrangé, 2019/08/08
- Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Stefan Hajnoczi, 2019/08/09
- Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Balamuruhan S, 2019/08/12
Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib,
Stefan Hajnoczi <=
Re: [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib, Daniel P . Berrangé, 2019/08/08
[Qemu-devel] [RFC PATCH 2/6] hw/ppc/pnv_xscom: extend xscom to use python interface, Balamuruhan S, 2019/08/07
[Qemu-devel] [RFC PATCH 3/6] hw/ppc/pnv_homer: add homer/occ common area emulation for PowerNV, Balamuruhan S, 2019/08/07