Module: kamailio
Branch: 4.4
Commit: 75f13d032b44fd520216101d38a4845f9d27b12e
URL:
https://github.com/kamailio/kamailio/commit/75f13d032b44fd520216101d38a4845…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-08-31T12:43:46+02:00
db_text: fix computing absolute path to db using cfg dir
- reported by GH #1224
(cherry picked from commit f74cddd78df3f37f6ea827fc1787796c601572b3)
(cherry picked from commit 630bf041fd0530368c73a6329c894a8758484ed7)
---
Modified: modules/db_text/dbt_base.c
Modified: modules/db_text/dbt_file.c
---
Diff:
https://github.com/kamailio/kamailio/commit/75f13d032b44fd520216101d38a4845…
Patch:
https://github.com/kamailio/kamailio/commit/75f13d032b44fd520216101d38a4845…
---
diff --git a/modules/db_text/dbt_base.c b/modules/db_text/dbt_base.c
index e8b3d1fc1d..c9ccb7fa43 100644
--- a/modules/db_text/dbt_base.c
+++ b/modules/db_text/dbt_base.c
@@ -52,6 +52,7 @@ db1_con_t* dbt_init(const str* _sqlurl)
LM_ERR("invalid parameter value\n");
return NULL;
}
+ LM_DBG("initializing for db url: [%.*s]\n", _sqlurl->len, _sqlurl->s);
_s.s = _sqlurl->s;
_s.len = _sqlurl->len;
if(_s.len <= DBT_ID_LEN || strncmp(_s.s, DBT_ID, DBT_ID_LEN)!=0)
@@ -68,16 +69,22 @@ db1_con_t* dbt_init(const str* _sqlurl)
_s.len -= DBT_ID_LEN;
if(_s.s[0]!='/')
{
- if(sizeof(CFG_DIR)+_s.len+2 > DBT_PATH_LEN)
+ if(sizeof(CFG_DIR)+_s.len+2 >= DBT_PATH_LEN)
{
LM_ERR("path to database is too long\n");
return NULL;
}
strcpy(dbt_path, CFG_DIR);
- dbt_path[sizeof(CFG_DIR)] = '/';
- strncpy(&dbt_path[sizeof(CFG_DIR)+1], _s.s, _s.len);
- _s.len += sizeof(CFG_DIR);
+ if(dbt_path[sizeof(CFG_DIR)-2]!='/') {
+ dbt_path[sizeof(CFG_DIR)-1] = '/';
+ strncpy(&dbt_path[sizeof(CFG_DIR)], _s.s, _s.len);
+ _s.len += sizeof(CFG_DIR);
+ } else {
+ strncpy(&dbt_path[sizeof(CFG_DIR)-1], _s.s, _s.len);
+ _s.len += sizeof(CFG_DIR) - 1;
+ }
_s.s = dbt_path;
+ LM_DBG("updated db url: [%.*s]\n", _s.len, _s.s);
}
_res = pkg_malloc(sizeof(db1_con_t)+sizeof(dbt_con_t));
diff --git a/modules/db_text/dbt_file.c b/modules/db_text/dbt_file.c
index eac2b73672..af4423c081 100644
--- a/modules/db_text/dbt_file.c
+++ b/modules/db_text/dbt_file.c
@@ -91,17 +91,18 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
dbt_table_p dtp = NULL;
dbt_column_p colp, colp0 = NULL;
dbt_row_p rowp, rowp0 = NULL;
-
+
enum {DBT_FLINE_ST, DBT_NLINE_ST, DBT_DATA_ST} state;
-
- LM_DBG("request for table [%.*s]\n", tbn->len, tbn->s);
-
+
if(!tbn || !tbn->s || tbn->len<=0 || tbn->len>=255)
return NULL;
+
+ LM_DBG("request for table [%.*s] (len: %d)\n", tbn->len, tbn->s,
tbn->len);
+
path[0] = 0;
if(dbn && dbn->s && dbn->len>0)
{
- LM_DBG("db is [%.*s]\n", dbn->len, dbn->s);
+ LM_DBG("db is [%.*s] (len: %d)\n", dbn->len, dbn->s, dbn->len);
if(dbn->len+tbn->len<511)
{
strncpy(path, dbn->s, dbn->len);
@@ -115,12 +116,14 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
strncpy(path, tbn->s, tbn->len);
path[tbn->len] = 0;
}
-
LM_DBG("loading file [%s]\n", path);
+
fin = fopen(path, "rt");
- if(!fin)
- return NULL;
-
+ if(!fin) {
+ LM_ERR("failed to open file [%s]\n", path);
+ return NULL;
+ }
+
buf = pkg_malloc(_db_text_read_buffer_size);
if(!buf) {
LM_ERR("error allocating read buffer, %i\n", _db_text_read_buffer_size);