# Why module shutdown function is not called for openssl extension?

- Thread: https://externals.io/message/13505
- Original archive: https://news-web.php.net/php.internals/13505
- Started by Kamesh Jayachandran on 2004-10-25T15:40:37+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13505 — Kamesh Jayachandran — 2004-10-25T15:40:37+00:00

URL: https://externals.io/message/13505#13505

Hi All,

I have identified a defect in openssl extension code. Even though it is
not critical and not likely to happen. Let me explain the scenario.
<?php
$dn = array(
    "countryName" => "TestCountry",
    "stateOrProvinceName" => "TestSrate",
    "localityName" => "TestLocality",
    "organizationName" => "Test Organisation",
    "organizationalUnitName" => "Test organisational Unit",
    "commonName" => "Test common name",
    "emailAddress" => "mymail@mail.com"
);
$privkey = `openssl_pkey_new()`;
$csr = openssl_csr_new($dn, $privkey);
?>
The above scenario causes a segfault in NetWare but not on Linux. I did
not try on windows.

openssl_csr_new will fail because maxlength of countryName is 2
characters.
During the failure openssl_csr_new is not setting req.priv_key to `NULL` 
this causes dispose function to free the req.priv_key.
As a part of php_request_shutdown $privkey is again freed(second time).
This causes a seg fault in NetWare.

Can I go ahead and set req.priv_key = `NULL` when php_openssl_make_REQ
returns failure and we_made_the_key == 0?


I have seen shutdown function is set to `NULL` even though it is defined.

With regards
Kamesh Jayachandran

---

## #13506 — Wez Furlong — 2004-10-25T15:49:17+00:00

URL: https://externals.io/message/13505#13506 · In reply to: #13505

Kamesh Jayachandran wrote:
> During the failure openssl_csr_new is not setting req.priv_key to `NULL` 
> this causes dispose function to free the req.priv_key.

> Can I go ahead and set req.priv_key = `NULL` when php_openssl_make_REQ
> returns failure and we_made_the_key == 0?

Please send me a diff

> I have seen shutdown function is set to `NULL` even though it is defined.

Which one?  Where?

--Wez

---

## #13515 — Kamesh Jayachandran — 2004-10-26T06:17:19+00:00

URL: https://externals.io/message/13505#13515 · In reply to: #13506

Hi Wez,

zend_module_entry openssl_module_entry = {
        STANDARD_MODULE_HEADER,
        "openssl",
        openssl_functions,
        PHP_MINIT(openssl),
        NULL, //supposed to be module shutdown function but marked as
        `NULL` even though we have MSHUTDOWN function defined.
        NULL,
        NULL,
        PHP_MINFO(openssl),
        NO_VERSION_YET,
        STANDARD_MODULE_PROPERTIES
};

My patch for making the req.priv_key not to get dispopsed is available
here.
http://puggy.symonds.net/~kameshj/openssl.c.patch

With regards
Kamesh Jayachandran
On Mon, 25 Oct 2004 16:49:17 +0100, "Wez Furlong" <wez@thebrainroom.com>
said:
> Kamesh Jayachandran wrote:
> > […]
> 
> > […]
> 
> Please send me a diff
> 
> > […]
> 
> Which one?  Where?
> 
> --Wez

---

## #13517 — Wez Furlong — 2004-10-26T09:34:19+00:00

URL: https://externals.io/message/13505#13517 · In reply to: #13515

Heh, looks like it's never ever been enabled since ext/openssl was born.

I committed your patch; the associated bug number was 29418.

Thanks :)

--Wez.


On Mon, 25 Oct 2004 23:17:19 -0700, Kamesh Jayachandran
<kameshj@fastmail.fm> wrote:
> Hi Wez,
> 
> zend_module_entry openssl_module_entry = {
>         STANDARD_MODULE_HEADER,
>         "openssl",
>         openssl_functions,
>         PHP_MINIT(openssl),
>         NULL, //supposed to be module shutdown function but marked as
>         `NULL` even though we have MSHUTDOWN function defined.
>         NULL,
>         NULL,
>         PHP_MINFO(openssl),
>         NO_VERSION_YET,
>         STANDARD_MODULE_PROPERTIES
> };
> 
> My patch for making the req.priv_key not to get dispopsed is available
> here.
> http://puggy.symonds.net/~kameshj/openssl.c.patch
> 
> With regards
> Kamesh Jayachandran
> On Mon, 25 Oct 2004 16:49:17 +0100, "Wez Furlong" <wez@thebrainroom.com>
> said:
> 
> 
> > […]

---

## #13518 — Kamesh Jayachandran — 2004-10-26T10:08:10+00:00

URL: https://externals.io/message/13505#13518 · In reply to: #13517

Thanks for applying my patches.

When will it be applied to PHP4.3 and 5.0 tree?

With regards
Kamesh Jayachandran
On Tue, 26 Oct 2004 10:34:19 +0100, "Wez Furlong" <kingwez@gmail.com>
said:
> Heh, looks like it's never ever been enabled since ext/openssl was born.
> 
> I committed your patch; the associated bug number was 29418.
> 
> Thanks :)
> 
> --Wez.
> 
> 
> On Mon, 25 Oct 2004 23:17:19 -0700, Kamesh Jayachandran
> <kameshj@fastmail.fm> wrote:
> > […]

---

## #13520 — Wez Furlong — 2004-10-26T10:13:44+00:00

URL: https://externals.io/message/13505#13520 · In reply to: #13518

It's already applied to all 3 branches.

--Wez.


On Tue, 26 Oct 2004 03:08:10 -0700, Kamesh Jayachandran
<kameshj@fastmail.fm> wrote:
> Thanks for applying my patches.
> 
> When will it be applied to PHP4.3 and 5.0 tree?
