Skip to content

Commit

Permalink
db_text: avoid buffer overflow for large names and/or values in db_te…
Browse files Browse the repository at this point in the history
…xt files

(cherry picked from commit 20febb2)
  • Loading branch information
ovidiusas committed May 10, 2019
1 parent 5f81141 commit 04a0a70
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/modules/db_text/dbt_file.c
Expand Up @@ -124,7 +124,7 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
return NULL;
}

buf = pkg_malloc(_db_text_read_buffer_size);
buf = pkg_malloc(_db_text_read_buffer_size+1);
if(!buf) {
LM_ERR("error allocating read buffer, %i\n", _db_text_read_buffer_size);
goto done;
Expand Down Expand Up @@ -173,6 +173,12 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
if(c==EOF)
goto clean;
buf[bp++] = c;
if (bp==_db_text_read_buffer_size) {
LM_ERR("Buffer overflow for file [%s] row=[%d] col=[%d] c=[%c]."
" Please increase 'file_buffer_size' param!\n",
path, crow+1, ccol+1, c);
goto clean;
}
c = fgetc(fin);
}
colp = dbt_column_new(buf, bp);
Expand Down Expand Up @@ -453,6 +459,12 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
}
}
buf[bp++] = c;
if (bp==_db_text_read_buffer_size) {
LM_ERR("Buffer overflow for file [%s] row=[%d] col=[%d] c=[%c]."
" Please increase 'file_buffer_size' param!\n",
path, crow+1, ccol+1, c);
goto clean;
}
c = fgetc(fin);
}
dtval.val.str_val.s = buf;
Expand Down

0 comments on commit 04a0a70

Please sign in to comment.