mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2026-01-11 19:09:35 +00:00
Fix GH-37: decryption of an encrypted empty string returns false (#50)
Closes GH-50
This commit is contained in:
parent
d3bbfee186
commit
c365ff0835
4 changed files with 34 additions and 5 deletions
1
NEWS.md
1
NEWS.md
|
|
@ -4,6 +4,7 @@ List of all features for the release
|
|||
|
||||
## X.Y.Z
|
||||
- The deletekey `allow_secret` made optional again
|
||||
- Fixed GH-37: `gnupg_decrypt()` returns false when decrypting an encrypted empty string
|
||||
|
||||
## 1.5.1
|
||||
- Fixed compilation with PHP 8.1
|
||||
|
|
|
|||
10
gnupg.c
10
gnupg.c
|
|
@ -1705,11 +1705,13 @@ PHP_FUNCTION(gnupg_decrypt)
|
|||
return;
|
||||
}
|
||||
userret = gpgme_data_release_and_get_mem(out, &ret_size);
|
||||
|
||||
gpgme_data_release(in);
|
||||
PHPC_CSTRL_RETVAL(userret, ret_size);
|
||||
free(userret);
|
||||
if (ret_size < 1) {
|
||||
RETVAL_FALSE;
|
||||
if (userret != NULL) {
|
||||
PHPC_CSTRL_RETVAL(userret, ret_size);
|
||||
free(userret);
|
||||
} else {
|
||||
PHPC_CSTR_EMPTY_RETVAL();
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
|
|
|||
2
phpc
2
phpc
|
|
@ -1 +1 @@
|
|||
Subproject commit 4521e6b11a3e578600772e4d2628a5f414fb60af
|
||||
Subproject commit 40078fd256965d76cddc060b7dd2e7849444f047
|
||||
26
tests/gnupg_oo_encrypt_empty_str.phpt
Normal file
26
tests/gnupg_oo_encrypt_empty_str.phpt
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
--TEST--
|
||||
encrypt and decrypt a text
|
||||
--SKIPIF--
|
||||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once "gnupgt.inc";
|
||||
gnupgt::import_key();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->addencryptkey($fingerprint);
|
||||
$enc = $gpg->encrypt("");
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg->adddecryptkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->decrypt($enc);
|
||||
var_dump($ret);
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(0) ""
|
||||
--CLEAN--
|
||||
<?php
|
||||
require_once "gnupgt.inc";
|
||||
gnupgt::delete_key();
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue