Module: kamailio
Branch: 5.0
Commit: 630bf041fd0530368c73a6329c894a8758484ed7
URL:
https://github.com/kamailio/kamailio/commit/630bf041fd0530368c73a6329c894a8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-08-31T12:39:54+02:00
db_text: fix computing absolute path to db using cfg dir
- reported by GH #1224
(cherry picked from commit f74cddd78df3f37f6ea827fc1787796c601572b3)
---
Modified: src/modules/db_text/dbt_base.c
Modified: src/modules/db_text/dbt_file.c
---
Diff:
https://github.com/kamailio/kamailio/commit/630bf041fd0530368c73a6329c894a8…
Patch:
https://github.com/kamailio/kamailio/commit/630bf041fd0530368c73a6329c894a8…
---
diff --git a/src/modules/db_text/dbt_base.c b/src/modules/db_text/dbt_base.c
index 667301268f..f965b22d24 100644
--- a/src/modules/db_text/dbt_base.c
+++ b/src/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/src/modules/db_text/dbt_file.c b/src/modules/db_text/dbt_file.c
index 4dfa9f53f6..66984bae5a 100644
--- a/src/modules/db_text/dbt_file.c
+++ b/src/modules/db_text/dbt_file.c
@@ -94,14 +94,15 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
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);
@@ -118,8 +119,10 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
LM_DBG("loading file [%s]\n", path);
fin = fopen(path, "rt");
- if(!fin)
+ if(!fin) {
+ LM_ERR("failed to open file [%s]\n", path);
return NULL;
+ }
buf = pkg_malloc(_db_text_read_buffer_size);
if(!buf) {