Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-22 Thread Jarrod Baumann
Confirmed that @ionutrazvanionita fixed the issue.  Thanks!

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-95189643___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-22 Thread Jarrod Baumann
Closed #471.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#event-287277064___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-22 Thread Ionut Ionita
fixed 0b6402c

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-95179737___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-20 Thread nixon
(I've never used opensips, and I haven't done any C coding in a decade.)

It seems to me that `new_db_id` takes a `str*` and assigns it to the `char* 
url` member of a `db_id` struct.  However, the `str*` relies on its `len` 
member, but the `url` member assumes a null-terminated string.  When the 
`db_id->url` is later passed to `sqlite3_open`, there's no guarantee that the 
string was null-terminated.

Is something like the following patch needed to ensure that `db_id` is always 
null-terminated for `sqlite3_open`?

```
diff --git a/db/db_id.c b/db/db_id.c
index 9efc0eb..c470324 100644
--- a/db/db_id.c
+++ b/db/db_id.c
@@ -240,7 +240,9 @@ struct db_id* new_db_id(const str* url)
}

/* store the original url */
-   ptr->url = url->s;
+   ptr->url = pkg_malloc(url->len+1);
+   strncpy(ptr->url, url->s, url->len);
+   ptr->url[url->len] = '\0';

return ptr;

@@ -291,5 +293,6 @@ void free_db_id(struct db_id* id)
if (id->password) pkg_free(id->password);
if (id->host) pkg_free(id->host);
if (id->database) pkg_free(id->database);
+   if (id->url) pkg_free(id->url);
pkg_free(id);
 }
```

I butchered up `main.c` to create a simple testcase.  Without the above patch, 
the `assert` fails.  With the patch, the `id->url` returned from `new_db_id` is 
what I would expect.

```
diff --git a/main.c b/main.c
index c44ebf2..4ebe8a0 100644
--- a/main.c
+++ b/main.c
@@ -770,8 +770,29 @@ error:
  * \return don't return on sucess, -1 on error
  * \see main_loop
  */
+#include 
 int main(int argc, char** argv)
 {
+   str s;
+   struct db_id* id;
+
+   /*init pkg mallocs (before parsing cfg but after parsing cmd line !)*/
+   if (init_pkg_mallocs()==-1)
+   goto error00;
+
+   // create a str object with a length of 23, but a longer string to
+   // simulate unallocated memory
+   //   11
+   //  12345678901234567890123
+   s.s  = "sqlite://tmp/0123456789ABCDEF";
+   s.len = 13  +10;
+
+   id = new_db_id(&s);
+
+   assert( strcmp(id->url, "sqlite://tmp/0123456789") == 0 );
+   exit(0);
+
+
```

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-94652782___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-20 Thread Jarrod Baumann
So digging into it more, I guess print is just looking for a terminating 
character \0, but still what is passed to sqlite3 for its call to openDatabase 
includes an extra byte on the end and that's whats causing the problem:

119274  in sqlite3.c
(gdb) s 
openDatabase (zFilename=0x7fffeecf30b8 "/var/db/opensips\b", 
ppDb=ppDb@entry=0x7fffe040, flags=flags@entry=6, zVfs=zVfs@entry=0x0) at 
sqlite3.c:121423


---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-94626123___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-20 Thread Jarrod Baumann
Thanks for the help ionut, here is the gdb output from drouting.c as we 
discussed in IRC:

```
Breakpoint 1, dr_init () at drouting.c:1176
1176if( head_start->db_url.s == 0 ) {
(gdb) n
1180memcpy( head_start->db_url.s, db_url.s, db_url.len );
(gdb) print db_url.s
$1 = 0x8a2140 "sqlite://var/db/opensips"
(gdb) print head_start->db_url.s
$2 = 0x7fffeecf1e00 ""
(gdb) n
1182init_head_w_extern_params();
(gdb) print head_start->db_url.s
$3 = 0x7fffeecf1e00 "sqlite://var/db/opensips\270\301\311\001"
(gdb) n
1184head_start->partition.s = "Default";
(gdb) print head_start->db_url.s
$4 = 0x7fffeecf1e00 "sqlite://var/db/opensips\030"
(gdb) 
```

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-94524290___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-20 Thread Ionut Ionita
@jarrodb https://gist.github.com/ionutrazvanionita/5f09ec2d96ddc60f6695 this 
patch fixes the bad '\0' issue.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-94515788___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-20 Thread Jarrod Baumann
Absolutely, every other module finds its version properly and the SQLite query 
built (query_holder) runs successfully on my database. 

However, the real problem is its trying to access the wrong SQLite path as 
noted by the newly created file in the same path as my actual database when the 
SQLite library attempts to read. 

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-94409599___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel


Re: [OpenSIPS-Devel] [opensips] modules/db_sqlite: error loading drouting (#471)

2015-04-20 Thread Bogdan Andrei IANCU
@jarrodb , do you have the "version" table created in your DB ? as the drouting 
module is looking into it to check the versions of the dr related tables.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/issues/471#issuecomment-94405269___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel