Skip to content

Commit

Permalink
DB modules: Improve error logs on failed conversions
Browse files Browse the repository at this point in the history
(cherry picked from commit 0819301)
  • Loading branch information
liviuchircu committed Jun 6, 2018
1 parent 72a8bc9 commit 27b0a14
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
9 changes: 6 additions & 3 deletions modules/db_mysql/val.c
Expand Up @@ -199,7 +199,8 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
case DB_STRING:
l = strlen(VAL_STRING(_v));
if (*_len < (l * 2 + 3)) {
LM_ERR("destination buffer too short\n");
LM_ERR("destination STRING buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -5;
} else {
old_s = _s;
Expand All @@ -214,7 +215,8 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len

case DB_STR:
if (*_len < (VAL_STR(_v).len * 2 + 3)) {
LM_ERR("destination buffer too short\n");
LM_ERR("destination STR buffer too short (have %d, need %d)\n",
*_len, VAL_STR(_v).len * 2 + 3);
return -6;
} else {
old_s = _s;
Expand All @@ -239,7 +241,8 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
case DB_BLOB:
l = VAL_BLOB(_v).len;
if (*_len < (l * 2 + 3)) {
LM_ERR("destination buffer too short\n");
LM_ERR("destination BLOB buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -8;
} else {
old_s = _s;
Expand Down
9 changes: 6 additions & 3 deletions modules/db_postgres/val.c
Expand Up @@ -238,7 +238,8 @@ int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v,
case DB_STRING:
l = strlen(VAL_STRING(_v));
if (*_len < (l * 2 + 3)) {
LM_ERR("destination buffer too short for string\n");
LM_ERR("destination STRING buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -4;
} else {
old_s = _s;
Expand All @@ -263,7 +264,8 @@ int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v,
case DB_STR:
l = VAL_STR(_v).len;
if (*_len < (l * 2 + 3)) {
LM_ERR("destination buffer too short for str\n");
LM_ERR("destination STR buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -5;
} else {
old_s = _s;
Expand Down Expand Up @@ -297,7 +299,8 @@ int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v,
l = VAL_BLOB(_v).len;
/* this estimation is not always correct, thus we need to check later again */
if (*_len < (l * 2 + 3)) {
LM_ERR("destination buffer too short for blob\n");
LM_ERR("destination BLOB buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -7;
} else {
*_s++ = '\'';
Expand Down
10 changes: 7 additions & 3 deletions modules/db_sqlite/val.c
Expand Up @@ -94,7 +94,9 @@ int db_sqlite_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _le
case DB_STRING:
l = strlen(VAL_STRING(_v));
if (*_len < l )
{ LM_ERR("Destination buffer too short for string\n");
{
LM_ERR("destination STRING buffer too short (have %d, need %d)\n",
*_len, l);
return -4;
}
else
Expand All @@ -112,7 +114,8 @@ int db_sqlite_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _le
l = VAL_STR(_v).len;
if (*_len < l)
{
LM_ERR("Destination buffer too short for str\n");
LM_ERR("destination STR buffer too short (have %d, need %d)\n",
*_len, l);
return -5;
}
else
Expand All @@ -139,7 +142,8 @@ int db_sqlite_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _le
l = VAL_BLOB(_v).len;
if (*_len < l)
{
LM_ERR("Destination buffer too short for blob\n");
LM_ERR("destination BLOB buffer too short (have %d, need %d)\n",
*_len, l);
return -7;
}
else
Expand Down
9 changes: 6 additions & 3 deletions modules/db_unixodbc/val.c
Expand Up @@ -257,7 +257,8 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _
l = strlen(VAL_STRING(_v));
if (*_len < (l * 2 + 3))
{
LM_ERR("destination buffer too short\n");
LM_ERR("destination STRING buffer too short "
"(have %d, need %d)\n", *_len, l * 2 + 3);
return -5;
}
else
Expand All @@ -282,7 +283,8 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _
l = VAL_STR(_v).len;
if (*_len < (l * 2 + 3))
{
LM_ERR("destination buffer too short\n");
LM_ERR("destination STR buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -6;
}
else
Expand Down Expand Up @@ -319,7 +321,8 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _
l = VAL_BLOB(_v).len;
if (*_len < (l * 2 + 3))
{
LM_ERR("destination buffer too short\n");
LM_ERR("destination BLOB buffer too short (have %d, need %d)\n",
*_len, l * 2 + 3);
return -8;
}
else
Expand Down

0 comments on commit 27b0a14

Please sign in to comment.