[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 19/23] libcacard: fix wrong array expansion logic
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 19/23] libcacard: fix wrong array expansion logic |
Date: |
Mon, 26 May 2014 11:20:07 +0400 |
The currrent code in libcacard/vcard_emul_nss.c:vcard_emul_options()
has a weird bug in variable usage around expanding opts->vreader
array.
There's a helper variable, vreaderOpt, which is first needlessly
initialized to NULL, next, conditionally, only we have to expand
opts->vreader, receives array expansion from g_renew(), and next,
even if we don't actually perform expansion, the value of this
variable is assigned to the actual array, opts->vreader, which
was supposed to be expanded.
So, since we expand the array by READER_STEP increments, only
once in READER_STEP (=4) the code will work, in other 3/4 times
it will fail badly.
Fix this by not using this temp variable when expanding the
array, and by dropping the useless =NULL initializer too -
if it wasn't in place initially, compiler would have warned
us about this problem at the beginning.
Signed-off-by: Michael Tokarev <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
---
libcacard/vcard_emul_nss.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index b7db51d..8462aef 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1149,7 +1149,7 @@ vcard_emul_options(const char *args)
char type_str[100];
VCardEmulType type;
int count, i;
- VirtualReaderOptions *vreaderOpt = NULL;
+ VirtualReaderOptions *vreaderOpt;
args = strip(args + 5);
if (*args != '(') {
@@ -1173,11 +1173,10 @@ vcard_emul_options(const char *args)
if (opts->vreader_count >= reader_count) {
reader_count += READER_STEP;
- vreaderOpt = g_renew(VirtualReaderOptions, opts->vreader,
- reader_count);
+ opts->vreader = g_renew(VirtualReaderOptions, opts->vreader,
+ reader_count);
}
- opts->vreader = vreaderOpt;
- vreaderOpt = &vreaderOpt[opts->vreader_count];
+ vreaderOpt = &opts->vreader[opts->vreader_count];
vreaderOpt->name = g_strndup(name, name_length);
vreaderOpt->vname = g_strndup(vname, vname_length);
vreaderOpt->card_type = type;
--
1.7.10.4
- [Qemu-trivial] [PULL 02/23] iohandler.c: Properly initialize sigaction struct, (continued)
- [Qemu-trivial] [PULL 02/23] iohandler.c: Properly initialize sigaction struct, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 05/23] configure: Automatically select GTK+ 3.0 if GTK+ 2.0 is unavailable, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 04/23] nbd: Miscellaneous typo fixes., Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 07/23] jazz_led: Add missing break in switch case, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 01/23] libcacard: g_malloc cleanups, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 08/23] pci: move dereferencing of root only after verifying valid root pointer, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 10/23] dma-helpers: avoid calling dma_bdrv_unmap() twice, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 13/23] libcacard/vscclient: Bury some dead code, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 21/23] bsd-user: replace fprintf(stderr, ...) with error_report(), Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 20/23] audio: replace fprintf(stderr, ...) with error_report() in audio, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 19/23] libcacard: fix wrong array expansion logic,
Michael Tokarev <=
- [Qemu-trivial] [PULL 14/23] libcacard: Plug memory leaks around vreader_get_reader_list(), Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 09/23] arch_init: replace fprintf(stderr, ...) with error_report(), Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 15/23] libcacard/vreader: Drop broken recovery from failed assertion, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 16/23] libcacard/vreader: Tighten assertion to clarify intent, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 23/23] libcacard: remove useless initializers, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 12/23] vl: fix 'name' option to work with -readconfig, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 06/23] bswap.h: Rename ldl_p, stl_p, etc to ldl_he_p, stl_he_p, etc, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 17/23] libcacard: Convert two leftover realloc() to GLib, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 22/23] net: cadence_gem: Fix top comment, Michael Tokarev, 2014/05/26
- [Qemu-trivial] [PULL 03/23] nbd: Close socket on negotiation failure., Michael Tokarev, 2014/05/26