aboutsummaryrefslogtreecommitdiff
path: root/libcacard/vcard_emul_nss.c
diff options
context:
space:
mode:
authorMichael Tokarev <mjt@tls.msk.ru>2014-05-24 00:47:39 +0400
committerMichael Tokarev <mjt@tls.msk.ru>2014-05-26 10:40:04 +0400
commitd09b8fa161ed6a61339d4d0870f76f13c033b2a3 (patch)
tree396818d311043e3e327604297fbdd9530ec8b19c /libcacard/vcard_emul_nss.c
parent42119fa3568dc7e8c82447c861678a5987d06d91 (diff)
libcacard: fix wrong array expansion logic
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 <mjt@tls.msk.ru> Reviewed-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'libcacard/vcard_emul_nss.c')
-rw-r--r--libcacard/vcard_emul_nss.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index b7db51df34..8462aefd3f 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;