Skip to content

Commit

Permalink
db_postgres: safety check of str buffer pointer before writing
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Oct 28, 2016
1 parent d7431dd commit 8ed8d83
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modules/db_postgres/pg_sql.c
Expand Up @@ -119,11 +119,11 @@ 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) {
asize = rsize - sb->size;
new_size = sb->size + (asize / sb->increment +
(asize % sb->increment > 0)) * sb->increment;
new_size = sb->size + (asize / sb->increment
+ (asize % sb->increment > 0)) * sb->increment;
newp = pkg_malloc(new_size);
if (!newp) {
ERR("postgres: No memory left\n");
Expand All @@ -136,8 +136,10 @@ static inline int sb_add(struct string_buffer *sb, str *nstr)
sb->s = newp;
sb->size = new_size;
}
memcpy(sb->s + sb->len, nstr->s, nstr->len);
sb->len += nstr->len;
if(sb->s) {
memcpy(sb->s + sb->len, nstr->s, nstr->len);
sb->len += nstr->len;
}
return 0;
}

Expand Down

0 comments on commit 8ed8d83

Please sign in to comment.