Package: opensc-pkcs11
Version: 0.16.0~rc2-1
Severity: minor
Tags: patch

The interaction with the DNIe UI does not work on Firefox because an
alarm interrupts the read operations, aborting the confirmation.
Description: Fix interaction with DNIe UI
 The interaction with the DNIe UI does not work on Firefox because an alarm
 interrupts the read operations, aborting the confirmation. This is fixed by
 using nointr_fgets(). There are side issues:
 * Forked process should abort on failure instead of continuing with OpenSC.
 * Useless initializations with memset().
 * Size adjustments in read and write operations.
Author: Javier Serrano Polo <jav...@jasp.net>
Forwarded: https://github.com/OpenSC/OpenSC/pull/789

Index: opensc-0.16.0~rc2/src/libopensc/card-dnie.c
===================================================================
--- opensc-0.16.0~rc2.orig/src/libopensc/card-dnie.c	2016-06-05 20:48:32.000000000 +0200
+++ opensc-0.16.0~rc2/src/libopensc/card-dnie.c	2016-06-06 01:42:11.000000000 +0200
@@ -162,6 +162,25 @@
 char *user_consent_msgs[] = { "SETTITLE", "SETDESC", "CONFIRM", "BYE" };
 
 /**
+ * Do fgets() without interruptions.
+ *
+ * Retry the operation if it is interrupted, such as with receiving an alarm.
+ *
+ * @param s Buffer receiving the data
+ * @param size Size of the buffer
+ * @param stream Stream to read
+ * @return s on success, NULL on error
+ */
+static char *nointr_fgets(char *s, int size, FILE *stream)
+{
+	while (fgets(s, size, stream) == NULL) {
+		if (feof(stream) || errno != EINTR)
+			return NULL;
+	}
+	return s;
+}
+
+/**
  * Ask for user consent.
  *
  * Check for user consent configuration,
@@ -283,9 +302,8 @@
 		/* call exec() with proper user_consent_app from configuration */
 		/* if ok should never return */
 		execlp(GET_DNIE_UI_CTX(card).user_consent_app, GET_DNIE_UI_CTX(card).user_consent_app, (char *)NULL);
-		res = SC_ERROR_INTERNAL;
-		msg = "execlp() error";	/* exec() failed */
-		goto do_error;
+		sc_log(card->ctx, "execlp() error");
+		abort();
 	default:		/* parent */
 		/* Close the pipe ends that the child uses to read from / write to
 		 * so when we close the others, an EOF will be transmitted properly.
@@ -304,22 +322,24 @@
 			goto do_error;
 		}
 		/* read and ignore first line */
-		fflush(stdin);
+		if (nointr_fgets(buf, sizeof(buf), fin) == NULL) {
+			res = SC_ERROR_INTERNAL;
+			msg = "nointr_fgets() Unexpected IOError/EOF";
+			goto do_error;
+		}
 		for (n = 0; n<4; n++) {
 			char *pt;
-			memset(outbuf, 0, sizeof(outbuf));
-			if (n==0) snprintf(outbuf,1023,"%s %s\n",user_consent_msgs[0],title);
-			else if (n==1) snprintf(outbuf,1023,"%s %s\n",user_consent_msgs[1],message);
-			else snprintf(outbuf,1023,"%s\n",user_consent_msgs[n]);
+			if (n==0) snprintf(outbuf, sizeof outbuf,"%s %s\n",user_consent_msgs[0],title);
+			else if (n==1) snprintf(outbuf, sizeof outbuf,"%s %s\n",user_consent_msgs[1],message);
+			else snprintf(outbuf, sizeof outbuf,"%s\n",user_consent_msgs[n]);
 			/* send message */
 			fputs(outbuf, fout);
 			fflush(fout);
 			/* get response */
-			memset(buf, 0, sizeof(buf));
-			pt=fgets(buf, sizeof(buf) - 1, fin);
+			pt=nointr_fgets(buf, sizeof(buf), fin);
 			if (pt==NULL) {
 				res = SC_ERROR_INTERNAL;
-				msg = "fgets() Unexpected IOError/EOF";
+				msg = "nointr_fgets() Unexpected IOError/EOF";
 				goto do_error;
 			}
 			if (strstr(buf, "OK") == NULL) {

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to