[Pkg-gnupg-commit] [gpgme] 166/412: python: Improve error handling.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 77d149e8614c381458e07808a7930ce3fb92cdc3
Author: Justus Winter <justus at g10code.com>
Date:   Wed Jun 8 18:06:24 2016 +0200

    python: Improve error handling.
    
    * lang/python/helpers.c (pyPassphraseCb): Handle write errors.
    (pyEditCb): Likewise.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 lang/python/helpers.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 5c620e6..0033ef0 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -320,7 +320,10 @@ static gpgme_error_t pyPassphraseCb(void *hook,
     err_status = pygpgme_exception2code();
   } else {
     if (!retval) {
-      write(fd, "\n", 1);
+      if (write(fd, "\n", 1) < 0) {
+        err_status = gpgme_error_from_syserror ();
+        pygpgme_raise_exception (err_status);
+      }
     } else {
       char *buf;
       size_t len;
@@ -342,8 +345,15 @@ static gpgme_error_t pyPassphraseCb(void *hook,
           goto leave;
         }
 
-      write(fd, buf, len);
-      write(fd, "\n", 1);
+      if (write(fd, buf, len) < 0) {
+        err_status = gpgme_error_from_syserror ();
+        pygpgme_raise_exception (err_status);
+      }
+      if (! err_status && write(fd, "\n", 1) < 0) {
+        err_status = gpgme_error_from_syserror ();
+        pygpgme_raise_exception (err_status);
+      }
+
       Py_DECREF(retval);
     }
   }
@@ -512,17 +522,24 @@ gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,
   Py_DECREF(pyargs);
   if (PyErr_Occurred()) {
     err_status = pygpgme_exception2code();
-    pygpgme_stash_callback_exception(self);
   } else {
     if (fd>=0 && retval && PyUnicode_Check(retval)) {
       const char *buffer;
       Py_ssize_t size;
 
       buffer = PyUnicode_AsUTF8AndSize(retval, &size);
-      write(fd, buffer, size);
-      write(fd, "\n", 1);
+      if (write(fd, buffer, size) < 0) {
+        err_status = gpgme_error_from_syserror ();
+        pygpgme_raise_exception (err_status);
+      }
+      if (! err_status && write(fd, "\n", 1) < 0) {
+        err_status = gpgme_error_from_syserror ();
+        pygpgme_raise_exception (err_status);
+      }
     }
   }
+  if (err_status)
+    pygpgme_stash_callback_exception(self);
 
   Py_XDECREF(retval);
   return err_status;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list