Fix GH-37: decryption of an encrypted empty string returns false (#50)

Closes GH-50
This commit is contained in:
Jakub Zelenka 2025-03-18 14:54:49 +01:00 committed by GitHub
parent d3bbfee186
commit c365ff0835
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 5 deletions

View file

@ -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
View file

@ -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

@ -1 +1 @@
Subproject commit 4521e6b11a3e578600772e4d2628a5f414fb60af
Subproject commit 40078fd256965d76cddc060b7dd2e7849444f047

View 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();
?>