From: Hamish <dmishd@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] Need help applying patches
Date: Sun, 20 Feb 2011 19:19:17 +0000 [thread overview]
Message-ID: <1298228733-sup-6115@whisper> (raw)
[-- Attachment #1: Type: text/plain, Size: 2060 bytes --]
Gaudenz has submitted a few useful patches which I want to commit to the
gpgme branch, but git apply seems to fail. I've forwarded the message
text below, and attached the patches. When I apply it gpgme, I get:
$ git apply --check --verbose ../patches2merge/0001-Unify-formatting-of-GPGME-error-messages.patch
Checking patch lib/sup/crypto.rb...
error: while searching for:
begin
sig = GPGME.detach_sign(format_payload(payload), gpg_opts)
rescue GPGME::Error => exc
info "Error while running gpg: #{exc.message}"
raise Error, "GPG command failed. See log for details."
end
envelope = RMail::Message.new
error: patch failed: lib/sup/crypto.rb:75
error: lib/sup/crypto.rb: patch does not apply
But I can't see why it could not find it. The code quoted above has
moved down by 31 lines, but is otherwise unchanged, but I thought git
could cope with that :/
I tried hand-editing the patch to change the line numbers, but I still
get the same error. Am I missing a trick? I've checked the file formats
and both have unix-style line endings.
I have tried and I can apply these patches by hand, but then they will
appear as committed by me, rather than giving Gaudenz his due.
Do others have the same problem? You could try by checking out the gpgme
branch and trying git apply.
I've also tried git am on a directory with these 3 attachments in:
$ git am -s ../patches2merge/
Nothing to do.
Not very helpful. Any help appreciated.
Hamish Downer
PS I am using git 1.7.1 on Ubuntu 10.10 x86_64
--- Begin forwarded message from Gaudenz Steinlin ---
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
To: sup-devel <sup-devel@rubyforge.org>
Date: Thu, 17 Feb 2011 14:49:01 +0000
Subject: [sup-devel] GPGME fixes
Hi
While reimporting all my messages I encountered a few problemes with
the GPGME code. Please consider the attached fixes.
The second patch depends on the first (error message unification). But
if you don't like the first I can easily produce a standalone version.
Gaudenz
--- End forwarded message ---
[-- Attachment #2: 0003-Check-for-valid-signature-before-signature.to_s.patch --]
[-- Type: application/octet-stream, Size: 1290 bytes --]
From 0a242c50f93319a47217dd577089732f4fbf0664 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:26:41 +0100
Subject: [PATCH 3/3] Check for valid signature before signature.to_s
In some circumstances with broken signatures signature.to_s returns nil.
Check for a valid signature before relying on this string. This avoids
an uncaught exception.
---
lib/sup/crypto.rb | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index cbd0751..9ab8607 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -292,7 +292,13 @@ private
ctx = GPGME::Ctx.new
begin
from_key = ctx.get_key(signature.fingerprint)
- first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
+ if GPGME::gpgme_err_code(signature.status) == GPGME::GPG_ERR_GENERAL
+ first_sig = "General error on signature verification for #{signature.fingerprint}"
+ elsif signature.to_s
+ first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
+ else
+ first_sig = "Unknown error or empty signature"
+ end
rescue EOFError
from_key = nil
first_sig = "No public key available for #{signature.fingerprint}"
--
1.7.2.3
[-- Attachment #3: 0002-Check-for-ArgumentError-on-signature-verification.patch --]
[-- Type: application/octet-stream, Size: 1614 bytes --]
From f86d0bb6c2cc9a1d8ef544a34f9c10f73850767c Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:13:31 +0100
Subject: [PATCH 2/3] Check for ArgumentError on signature verification
Broken signatures can cause a NULL pointer which results in an
ArguementError when calling ctx.verify_result even if the previous call
to ctx.verify does not raise an exception.
The underling cause is probably a bug in GPGME.
---
lib/sup/crypto.rb | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index a3771bf..cbd0751 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -183,7 +183,11 @@ EOS
rescue GPGME::Error => exc
return unknown_status [gpgme_exc_msg(exc.message)]
end
- self.verified_ok? ctx.verify_result
+ begin
+ self.verified_ok? ctx.verify_result
+ rescue ArgumentError => exc
+ return unknown_status [gpgme_exc_msg(exc.message)]
+ end
end
## returns decrypted_message, status, desc, lines
@@ -201,7 +205,11 @@ EOS
rescue GPGME::Error => exc
return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", gpgme_exc_msg(exc.message))
end
- sig = self.verified_ok? ctx.verify_result
+ begin
+ sig = self.verified_ok? ctx.verify_result
+ rescue ArgumentError => exc
+ sig = unknown_status [gpgme_exc_msg(exc.message)]
+ end
plain_data.seek(0, IO::SEEK_SET)
output = plain_data.read
output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
--
1.7.2.3
[-- Attachment #4: 0001-Unify-formatting-of-GPGME-error-messages.patch --]
[-- Type: application/octet-stream, Size: 2413 bytes --]
From b52a306ed119715e5dac26f35a406ecdd4c5fb87 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:09:23 +0100
Subject: [PATCH 1/3] Unify formatting of GPGME error messages
Create a private function to turn a an exception into a "human friendly"
error message and to add a entry to the logfile. Use this function for
all error paths.
---
lib/sup/crypto.rb | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 2bfb475..a3771bf 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -75,8 +75,7 @@ EOS
begin
sig = GPGME.detach_sign(format_payload(payload), gpg_opts)
rescue GPGME::Error => exc
- info "Error while running gpg: #{exc.message}"
- raise Error, "GPG command failed. See log for details."
+ raise Error, gpgme_exc_msg(exc.message)
end
envelope = RMail::Message.new
@@ -103,8 +102,7 @@ EOS
begin
cipher = GPGME.encrypt(recipients, format_payload(payload), gpg_opts)
rescue GPGME::Error => exc
- info "Error while running gpg: #{exc.message}"
- raise Error, "GPG command failed. See log for details."
+ raise Error, gpgme_exc_msg(exc.message)
end
encrypted_payload = RMail::Message.new
@@ -183,7 +181,7 @@ EOS
begin
ctx.verify(sig_data, signed_text_data, plain_data)
rescue GPGME::Error => exc
- return unknown_status exc.message
+ return unknown_status [gpgme_exc_msg(exc.message)]
end
self.verified_ok? ctx.verify_result
end
@@ -201,8 +199,7 @@ EOS
begin
ctx.decrypt_verify(cipher_data, plain_data)
rescue GPGME::Error => exc
- info "Error while running gpg: #{exc.message}"
- return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", exc.message)
+ return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", gpgme_exc_msg(exc.message))
end
sig = self.verified_ok? ctx.verify_result
plain_data.seek(0, IO::SEEK_SET)
@@ -264,6 +261,12 @@ private
["Can't find gpgme gem."]
end
+ def gpgme_exc_msg msg
+ err_msg = "Exception in GPGME call: #{msg}"
+ info err_msg
+ err_msg
+ end
+
## here's where we munge rmail output into the format that signed/encrypted
## PGP/GPG messages should be
def format_payload payload
--
1.7.2.3
[-- Attachment #5: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next reply other threads:[~2011-02-20 19:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-20 19:19 Hamish [this message]
2011-02-20 19:55 ` Hamish
2011-02-22 13:14 ` Gaudenz Steinlin
2011-02-20 20:12 ` Michael Hamann
2011-02-20 21:58 ` William Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1298228733-sup-6115@whisper \
--to=dmishd@gmail.com \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox