[evolution-data-server] I#75 - Sometimes fails to properly decrypt large GPG encrypted messages



commit 5cd59aee67450e8750eb3cb2d357d0947f199f61
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 7 21:01:03 2019 +0100

    I#75 - Sometimes fails to properly decrypt large GPG encrypted messages
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/issues/75

 src/camel/camel-gpg-context.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/src/camel/camel-gpg-context.c b/src/camel/camel-gpg-context.c
index 0b884a583..1b3362886 100644
--- a/src/camel/camel-gpg-context.c
+++ b/src/camel/camel-gpg-context.c
@@ -1518,11 +1518,35 @@ gpg_ctx_op_step (struct _GpgCtx *gpg,
                if (nread > 0) {
                        if (gpg->mode != GPG_CTX_MODE_DECRYPT ||
                            gpg->in_decrypt_stage || was_in_decrypt_stage) {
-                               gsize written = camel_stream_write (
-                                       gpg->ostream, buffer, (gsize)
-                                       nread, cancellable, error);
-                               if (written != nread)
-                                       return -1;
+                               gboolean done = FALSE;
+
+                               while (!done) {
+                                       gsize written = camel_stream_write (
+                                               gpg->ostream, buffer, (gsize)
+                                               nread, cancellable, error);
+                                       if (written != nread)
+                                               return -1;
+
+                                       done = TRUE;
+
+                                       /* Read everything cached */
+                                       do {
+                                               polls[0].revents = 0;
+                                               status = g_poll (polls, 1, 5);
+                                       } while (status == -1 && errno == EINTR);
+
+                                       if (status != -1 && status != 0 && (polls[0].revents & (G_IO_IN | 
G_IO_HUP))) {
+                                               do {
+                                                       nread = read (gpg->stdout_fd, buffer, sizeof 
(buffer));
+                                                       d (printf ("   cached read %d bytes (%.*s)\n", (gint) 
nread, (gint) nread, buffer));
+                                               } while (nread == -1 && (errno == EINTR || errno == EAGAIN));
+
+                                               if (nread == -1)
+                                                       goto exception;
+
+                                               done = !nread;
+                                       }
+                               }
                        } else {
                                if (!gpg->decrypt_extra_text)
                                        gpg->decrypt_extra_text = g_string_new ("");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]