[sr-dev] git:master:97db3ee6: db_mysql: safer conditions inside sb_add() for db api v2
Daniel-Constantin Mierla
miconda at gmail.com
Fri Jul 28 09:19:30 CEST 2017
Module: kamailio
Branch: master
Commit: 97db3ee61079de6cc2466628dae0f5e489819e98
URL: https://github.com/kamailio/kamailio/commit/97db3ee61079de6cc2466628dae0f5e489819e98
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-28T09:19:06+02:00
db_mysql: safer conditions inside sb_add() for db api v2
---
Modified: src/modules/db_mysql/my_cmd.c
---
Diff: https://github.com/kamailio/kamailio/commit/97db3ee61079de6cc2466628dae0f5e489819e98.diff
Patch: https://github.com/kamailio/kamailio/commit/97db3ee61079de6cc2466628dae0f5e489819e98.patch
---
diff --git a/src/modules/db_mysql/my_cmd.c b/src/modules/db_mysql/my_cmd.c
index 7872568b29..8502e6d323 100644
--- a/src/modules/db_mysql/my_cmd.c
+++ b/src/modules/db_mysql/my_cmd.c
@@ -372,8 +372,10 @@ static inline int sb_add(struct string_buffer *sb, str *nstr)
int rsize = sb->len + nstr->len;
int asize;
char *newp;
-
- if ( rsize > sb->size ) {
+
+ if(nstr->len==0) return 0;
+
+ if ( sb->s==NULL || rsize > sb->size ) {
asize = rsize - sb->size;
new_size = sb->size + (asize / sb->increment + (asize % sb->increment > 0)) * sb->increment;
newp = pkg_malloc(new_size);
@@ -423,6 +425,9 @@ static int build_update_cmd(str* sql_cmd, db_cmd_t* cmd)
rv = sb_add(&sql_buf, &strings[STR_UPDATE]); /* "UPDATE " */
rv |= sb_add(&sql_buf, &cmd->table); /* table name */
rv |= sb_add(&sql_buf, &strings[STR_SET]); /* " SET " */
+ if (rv) {
+ goto err;
+ }
/* column name-value pairs */
for(i = 0, fld = cmd->vals; !DB_FLD_LAST(fld[i]); i++) {
More information about the sr-dev
mailing list