Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on pg_connect (pgsql extension) #353

Closed
kkovacs opened this issue Feb 25, 2024 · 4 comments · Fixed by #355
Closed

Segfault on pg_connect (pgsql extension) #353

kkovacs opened this issue Feb 25, 2024 · 4 comments · Fixed by #355
Labels
bug Something isn't working kind/extension Issues related to extensions

Comments

@kkovacs
Copy link

kkovacs commented Feb 25, 2024

Apparently static-php-cli segfaults on the pg_connect call.

Steps to reproduce:

$ ./spc download --for-extensions=pgsql
$ ./spc doctor --auto-fix
$ ./spc build --build-cli pgsql
$ ./buildroot/bin/php index.php

Warning: pg_connect(): Unable to connect to PostgreSQL server: connection to server at "127.0.0.1", port 5432 failed: FATAL:  no PostgreSQL user name specified in startup packet
connection to server at "127.0.0.1", port 5432 failed: FATAL:  no PostgreSQL user name specified in startup packet in /persist/lara4/foo.php on line 2
Segmentation fault (core dumped)

Where index.php is:

<?php
pg_connect("postgresql://root:xxxxx@127.0.0.1/postgres");

or alternatively (with same result):

<?php
pg_connect("host=127.0.0.1 dbname=postgres user=root password=xxxxx");

Tested with Ubuntu 23.10 and Ubuntu 22.04, x86_64 architecture.

The no PostgreSQL user name specified in startup packet is especially interesting, since there IS clearly a username specified in the connection string?

@crazywhalecc crazywhalecc added bug Something isn't working kind/extension Issues related to extensions labels Feb 26, 2024
@crazywhalecc
Copy link
Owner

crazywhalecc commented Feb 26, 2024

This issue seems related to:

If this issue is caused by connecting pgsql server with ssl, I will review it again this week.

EDIT: postgresql 16.2 fixed the openssl bug, I'll update spc's postgresql library version and release it.

@kkovacs
Copy link
Author

kkovacs commented Feb 26, 2024

Dear @crazywhalecc,

you're entirely right -- this DOES seem related to SSL, since the bug doesn't happen with sslmode=disable:

<?php
$conn = pg_connect("postgresql://root:xxxxx@127.0.0.1/postgres?sslmode=disable");
$result = pg_query($conn, "select version()");
var_dump(pg_fetch_all($result));

No segfault:

$ ./buildroot/bin/php foo.php
array(1) {
  [0]=>
  array(1) {
    ["version"]=>
    string(134) "PostgreSQL 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit"
  }
}

If you can update the library, that would be awesome.

P.s.: Thanks for all the great things you are doing for the PHP community! 🙇

@crazywhalecc
Copy link
Owner

crazywhalecc commented Feb 26, 2024

#355

I tested on macOS with 16.2 and it works good with sslmode=require. I cannot test on my linux cuz no pgsql server on my linux vm.

But building everything is perfect for now (despite buggy workflow for setup-php), I'll update main branch soon .

Remember deleting download cache.

@kkovacs
Copy link
Author

kkovacs commented Feb 26, 2024

Thank you for the quick action! I can confirm, building from master now it works with sslmode=require for me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kind/extension Issues related to extensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants