Andreas Jellinghaus wrote:
...
@@ -758,10 +758,14 @@
                                SC_PKCS15_AODF, NULL);
        }

-       if (r >= 0)
+       if (r >= 0) {
                r = sc_pkcs15init_update_dir(p15spec, profile, app);
-       if (r >= 0)
-               r = sc_pkcs15init_update_tokeninfo(p15spec, profile);
+
+               if (r >= 0)
+                       r = sc_pkcs15init_update_tokeninfo(p15spec, profile);
+       } else {
+               free(app); /* unused */
+       }
hmm, if sc_pkcs15init_update_dir() fails we still have a possible memory
leak (unfortunately it's not clear whether we need to free app or not when
sc_pkcs15init_update() returns an error)

right. so the fix is incomplete, but still fixes a part of the problem.
commit this fix and open a bug for the remaining hole?

what about the attached patch ?


--- src/libopensc/apdu.c        (revision 2919)
+++ src/libopensc/apdu.c        (working copy)
@@ -222,14 +222,15 @@
        }
        /* set the SW1 and SW2 status bytes (the last two bytes of
         * the response */
-       apdu->sw1 = (unsigned int)buf[len - 2];
-       apdu->sw2 = (unsigned int)buf[len - 1];
+       apdu->sw1 = buf[len - 2];
+       apdu->sw2 = buf[len - 1];
the casts here should suppress a warning when turning on some gcc
warning options afaik

I wonder which one. assigning a char or unsigned char to an int should
always be fine I thought. but we can drop that part as well.

as far as I remember did the compiler complain about the different width
of both types


--- src/libopensc/log.c (revision 2919)
+++ src/libopensc/log.c (working copy)
@@ -98,8 +98,8 @@
        }

        if (file != NULL) {
-               r = snprintf(buf, sizeof(buf)-1, "%s:%d:%s: ", file, line, func 
? func
: ""); -              if (r < 0 || (unsigned int)r >= sizeof(buf))
+               r = snprintf(buf, sizeof(buf), "%s:%d:%s: ", file, line, func ? 
func :
""); +                if (r < 0 || (unsigned int)r > sizeof(buf))
                        return;
should we really discard the debug data when the printed value has been
truncated ?

right, might not be a good strategy anyway.
change the code to display as much as we can?
log a second line about output being truncated?

I'm not sure but I think it would make sense to show as much information
as possible and perhaps (optional) give a hint that the information has
been truncated.

Cheers,
Nils
Index: src/pkcs15init/pkcs15-lib.c
===================================================================
--- src/pkcs15init/pkcs15-lib.c	(Revision 2922)
+++ src/pkcs15init/pkcs15-lib.c	(Arbeitskopie)
@@ -88,7 +88,7 @@
 
 static int	sc_pkcs15init_update_dir(struct sc_pkcs15_card *,
 			struct sc_profile *profile,
-			sc_app_info_t *app);
+			sc_app_info_t **app);
 static int	sc_pkcs15init_update_tokeninfo(struct sc_pkcs15_card *,
 			struct sc_profile *profile);
 static int	sc_pkcs15init_update_odf(struct sc_pkcs15_card *,
@@ -604,7 +604,7 @@
 	sc_pkcs15_card_t	*p15spec = profile->p15_spec;
 	sc_pkcs15_pin_info_t	pin_info, puk_info;
 	sc_pkcs15_object_t	*pin_obj = NULL;
-	sc_app_info_t	*app;
+	sc_app_info_t		*app = NULL;
 	sc_file_t		*df = profile->df_info->file;
 	int			r;
 
@@ -759,10 +759,18 @@
 	}
 
 	if (r >= 0)
-		r = sc_pkcs15init_update_dir(p15spec, profile, app);
+		r = sc_pkcs15init_update_dir(p15spec, profile, &app);
 	if (r >= 0)
 		r = sc_pkcs15init_update_tokeninfo(p15spec, profile);
 
+	if (app != NULL) {
+		if (app->label != NULL)
+			free(app->label);
+		if (app->ddo   != NULL)
+			free(app->ddo);
+		free(app);
+	}
+
 	sc_ctx_suppress_errors_on(card->ctx);
 	sc_pkcs15init_write_info(card, profile, pin_obj);
 	sc_ctx_suppress_errors_off(card->ctx);
@@ -2323,7 +2331,7 @@
 static int
 sc_pkcs15init_update_dir(struct sc_pkcs15_card *p15card,
 		struct sc_profile *profile,
-		sc_app_info_t *app)
+		sc_app_info_t **app)
 {
 	sc_card_t *card = p15card->card;
 	int	r, retry = 1;
@@ -2347,7 +2355,8 @@
 	} while (retry--);
 
 	if (r >= 0) {
-		card->app[card->app_count++] = app;
+		card->app[card->app_count++] = *app;
+		*app = NULL;
 		r = sc_update_dir(card, NULL);
 	}
 	return r;
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to