[asterisk-bugs] [JIRA] (ASTERISK-28435) cdr_pgsql: Unix socket doesn't work

Kevin Harwell (JIRA) noreply at issues.asterisk.org
Mon Jun 3 17:57:49 CDT 2019


    [ https://issues.asterisk.org/jira/browse/ASTERISK-28435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=247290#comment-247290 ] 

Kevin Harwell edited comment on ASTERISK-28435 at 6/3/19 5:57 PM:
------------------------------------------------------------------

Hi Dmitry, thank you very much for your collaboration.

The following code will do a better job, since it also checks for the values of each parameter, using internal asterisk function ast_strlen_zero() which is actually used a couple of lines later in the same function.

I am going to proceed to submit the code to Gerrit for review, unless you prefer to do it yourself, in which case I will look for your reply back. otherwise if I don't hear from you I will take it you want me to submit it.

Thank you and best regards

<edit to remove inline patch>


was (Author: csavinovich):
Hi Dmitry, thank you very much for your collaboration.

The following code will do a better job, since it also checks for the values of each parameter, using internal asterisk function ast_strlen_zero() which is actually used a couple of lines later in the same function.

I am going to proceed to submit the code to Gerrit for review, unless you prefer to do it yourself, in which case I will look for your reply back. otherwise if I don't hear from you I will take it you want me to submit it.

Thank you and best regards
(disregard my tabs)
```
static void pgsql_reconnect(void)
{
>---struct ast_str *conn_info = ast_str_create(128);
>---if (!conn_info) {
>--->---ast_log(LOG_ERROR, "Failed to allocate memory for connection string.\n");
>--->---return;
>---}

>---if (conn) {
>--->---PQfinish(conn);
>--->---conn = NULL;
>---}

>---if (!ast_strlen_zero(pghostname)) {
>--->---ast_str_append(&conn_info, 0, "host=%s ", pghostname);
>---}
>---if (!ast_strlen_zero(pgdbport)) {
>--->---ast_str_append(&conn_info, 0, "port=%s ", pgdbport);
>---}
>---if (!ast_strlen_zero(pgdbname)) {
>--->---ast_str_append(&conn_info, 0, "dbname=%s ", pgdbname);
>---}
>---if (!ast_strlen_zero(pgdbuser)) {
>--->---ast_str_append(&conn_info, 0, "user=%s ", pgdbuser);
>---}
>---if (!ast_strlen_zero(pgappname)) {
>--->---ast_str_append(&conn_info, 0, "application_name=%s ", pgappname);
>---}
>---if (!ast_strlen_zero(pgpassword)) {
>--->---ast_str_append(&conn_info, 0, "password=%s", pgpassword);
>---}
>---if (ast_str_strlen(conn_info) > 0) {
>--->---ast_log(LOG_ERROR, "Connection string is blank.\n");
>--->---return;
>---}

>---conn = PQconnectdb(ast_str_buffer(conn_info));
>---ast_free(conn_info);
}
```


> cdr_pgsql: Unix socket doesn't work
> -----------------------------------
>
>                 Key: ASTERISK-28435
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-28435
>             Project: Asterisk
>          Issue Type: Bug
>      Security Level: None
>          Components: CDR/cdr_pgsql
>    Affects Versions: 16.3.0
>            Reporter: Dmitry Svyatogorov
>
> After refactoring, function pgsql_reconnect() does "ast_str_set()" with statically composed string:
> {code}
> ast_str_set(&conn_info, 0, "host=%s port=%s dbname=%s user=%s"
> {code}
> It results in error while trying to connect to unix socket (empty host and port in config), so it's a regression.
> I propose the simple check:
> {code}
> static void pgsql_reconnect(void)
> ...
> 	if (!strcmp(pghostname, "")) {
> 		// UNIX socket
> 		ast_str_set(&conn_info, 0, "dbname=%s user=%s",
> 			pgdbname, pgdbuser);
> 	} else {
> 		// IP socket
> 		ast_str_set(&conn_info, 0, "host=%s port=%s dbname=%s user=%s",
> 			pghostname, pgdbport, pgdbname, pgdbuser);
> 	}
> {code}
> This patch works for me. _But m.b. there is more clear way?_



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list