Skip to content

Commit

Permalink
Fixed improper handling of snprintf return value
Browse files Browse the repository at this point in the history
... and fix improper snprintf buffer size broken by
703d69b
  • Loading branch information
yumkam committed Feb 10, 2016
1 parent 5b58925 commit 58fe3d2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/tcbtdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ set_dbparam (char *params, int len, const char *fmt, ...)
va_list args;

va_start (args, fmt);
n = vsnprintf (params + len, DB_PARAMS, fmt, args);
n = vsnprintf (params + len, DB_PARAMS - len, fmt, args);
va_end (args);

if (n < 0) {
// XXX log error
n = 0;
} else if (n >= DB_PARAMS - len) {
// XXX log truncation
n = DB_PARAMS - len;
}

return n;
}

Expand All @@ -79,7 +87,6 @@ tc_db_get_params (char *params, const char *path)

/* copy path name to buffer */
len += set_dbparam (params, len, "%s", path);
/*len += snprintf (params + len, DB_PARAMS - len, "%s", path); */

/* caching parameters of a B+ tree database object */
lcnum = conf.cache_lcnum > 0 ? conf.cache_lcnum : TC_LCNUM;
Expand Down

0 comments on commit 58fe3d2

Please sign in to comment.