Skip to content

Commit

Permalink
Revert "db_postgres: Fix heap use after free error in db_postgres mod…
Browse files Browse the repository at this point in the history
…ule" (after some discussions)

This reverts commit 74c84c7.
  • Loading branch information
carstenbock committed Sep 17, 2015
1 parent ee3d24d commit f83a695
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions modules/db_postgres/km_pg_con.c
Expand Up @@ -71,6 +71,10 @@ struct pg_con* db_postgres_new_connection(struct db_id* id)
memset(ptr, 0, sizeof(struct pg_con));
ptr->ref = 1;

memset(keywords, 0, (sizeof(char*) * 10));
memset(values, 0, (sizeof(char*) * 10));
memset(to, 0, (sizeof(char) * 16));

if (id->port) {
ports = int2str(id->port, 0);
keywords[i] = "port";
Expand Down
10 changes: 2 additions & 8 deletions modules/db_postgres/km_res.c
Expand Up @@ -126,14 +126,8 @@ int db_postgres_get_columns(const db1_con_t* _h, db1_res_t* _r)
RES_NAMES(_r)[col]);

/* The pointer that is here returned is part of the result structure. */
RES_NAMES(_r)[col]->s = pkg_malloc(strlen(PQfname(CON_RESULT(_h), col))+1);
if (! RES_NAMES(_r)[col]->s) {
LM_ERR("no private memory left\n");
db_free_columns(_r);
return -4;
}
strcpy(RES_NAMES(_r)[col]->s, PQfname(CON_RESULT(_h), col));
RES_NAMES(_r)[col]->len = strlen(RES_NAMES(_r)[col]->s);
RES_NAMES(_r)[col]->s = PQfname(CON_RESULT(_h), col);
RES_NAMES(_r)[col]->len = strlen(PQfname(CON_RESULT(_h), col));

LM_DBG("RES_NAMES(%p)[%d]=[%.*s]\n", RES_NAMES(_r)[col], col,
RES_NAMES(_r)[col]->len, RES_NAMES(_r)[col]->s);
Expand Down

0 comments on commit f83a695

Please sign in to comment.