all: fix potential buffer overflows, use vscnprintf()

This commit is contained in:
Thomas Schoebel-Theuer 2014-02-18 07:56:17 +01:00 committed by Thomas Schoebel-Theuer
parent e6abaaa161
commit 3e9aae53c8
9 changed files with 18 additions and 18 deletions

View File

@ -436,10 +436,10 @@ void _say(struct say_channel *ch, int class, va_list args, bool use_args, const
if (use_args) {
va_list args2;
va_start(args2, fmt);
written = vsnprintf(start, rest, fmt, args2);
written = vscnprintf(start, rest, fmt, args2);
va_end(args2);
} else {
written = vsnprintf(start, rest, fmt, args);
written = vscnprintf(start, rest, fmt, args);
}
if (likely(rest > written)) {
@ -730,7 +730,7 @@ void treat_channel(struct say_channel *ch, int class)
struct timespec s_now = CURRENT_TIME;
struct timespec l_now;
get_lamport(&l_now);
len = snprintf(buf,
len = scnprintf(buf,
SAY_BUFMAX,
"%ld.%09ld %ld.%09ld %s %d OVERFLOW %d times\n",
s_now.tv_sec, s_now.tv_nsec,

View File

@ -23,7 +23,7 @@ int report_timing(struct timing_stats *tim, char *str, int maxlen)
int i;
for (i = 0; i < TIMING_MAX; i++) {
int this_len = snprintf(str, maxlen, "<%d%s = %d (%lld) ", resol, unit, tim->tim_count[i], (long long)tim->tim_count[i] * time);
int this_len = scnprintf(str, maxlen, "<%d%s = %d (%lld) ", resol, unit, tim->tim_count[i], (long long)tim->tim_count[i] * time);
str += this_len;
len += this_len;
maxlen -= this_len;

View File

@ -114,7 +114,7 @@ static void dump_mem(void *data, int len)
}
tmp = buf;
}
tmp += snprintf(tmp, 1024 - i * 3, " %02x", byte);
tmp += scnprintf(tmp, 1024 - i * 3, " %02x", byte);
}
if (tmp != buf) {
say(-1, "%4d: %s\n", i, buf);

View File

@ -188,7 +188,7 @@ void mars_log(const char *fmt, ...)
return;
va_start(args, fmt);
len = vsnprintf(buf, PAGE_SIZE, fmt, args);
len = vscnprintf(buf, PAGE_SIZE, fmt, args);
va_end(args);
_mars_log(buf, len);
@ -228,16 +228,16 @@ void mars_log_trace(struct mref_object *mref)
diff = mref->ref_trace_stamp[mref->ref_traces-1] - mref->ref_trace_stamp[0];
len = snprintf(buf, PAGE_SIZE, "%c ;%12lld ;%6d;%10llu", mref->ref_rw ? 'W' : 'R', mref->ref_pos, mref->ref_len, diff / 1000);
len = scnprintf(buf, PAGE_SIZE, "%c ;%12lld ;%6d;%10llu", mref->ref_rw ? 'W' : 'R', mref->ref_pos, mref->ref_len, diff / 1000);
old = start_trace_clock;
for (i = 0; i < mref->ref_traces; i++) {
diff = mref->ref_trace_stamp[i] - old;
len += snprintf(buf + len, PAGE_SIZE - len, " ; %s ;%10llu", mref->ref_trace_info[i], diff / 1000);
len += scnprintf(buf + len, PAGE_SIZE - len, " ; %s ;%10llu", mref->ref_trace_info[i], diff / 1000);
old = mref->ref_trace_stamp[i];
}
len +=snprintf(buf + len, PAGE_SIZE - len, "\n");
len +=scnprintf(buf + len, PAGE_SIZE - len, "\n");
_mars_log(buf, len);

View File

@ -614,7 +614,7 @@ int _add_fields(struct mars_desc_item *mi, const struct meta *meta, int offset,
goto done;
}
len = snprintf(mi->field_name, MAX_FIELD_LEN, "%s.%s", prefix, meta->field_name);
len = scnprintf(mi->field_name, MAX_FIELD_LEN, "%s.%s", prefix, meta->field_name);
if (unlikely(len >= MAX_FIELD_LEN)) {
MARS_ERR("field len overflow on '%s.%s'\n", prefix, meta->field_name);
count = -1;

View File

@ -4737,7 +4737,7 @@ char *_mars_info(void)
struct mars_brick *test;
brick_count++;
test = container_of(tmp, struct mars_brick, global_brick_link);
pos += snprintf(
pos += scnprintf(
txt + pos, max - pos,
"brick button=%d off=%d on=%d path='%s'\n",
test->power.button,
@ -4754,7 +4754,7 @@ char *_mars_info(void)
dent_count++;
dent = container_of(tmp, struct mars_dent, dent_link);
#if 0 // usually there is not enough space in PAGE_SIZE
pos += snprintf(
pos += scnprintf(
txt + pos, max - pos,
"dent stamp=%ld.%09ld path='%s' value='%s'\n",
dent->new_stat.mtime.tv_sec, dent->new_stat.mtime.tv_nsec,
@ -4765,7 +4765,7 @@ char *_mars_info(void)
}
up_read(&mars_global->dent_mutex);
pos += snprintf(
pos += scnprintf(
txt + pos, max - pos,
"SUMMARY: brick_count=%d dent_count=%d\n",
brick_count,

View File

@ -133,7 +133,7 @@ int lamport_sysctl_handler(
get_lamport(&lnow);
res = snprintf(tmp, len,
res = scnprintf(tmp, len,
"CURRENT_TIME=%ld.%09ld\n"
"lamport_now=%ld.%09ld\n",
know.tv_sec, know.tv_nsec,

View File

@ -1455,7 +1455,7 @@ char *_backskip_replace(int line, const char *path, char delim, bool insert, con
memcpy(res, path, pos);
va_start(args, fmt);
plus = vsnprintf(res + pos, total_len - pos, fmt, args);
plus = vscnprintf(res + pos, total_len - pos, fmt, args);
va_end(args);
if (insert) {

View File

@ -141,7 +141,7 @@ int make_dirs(char *out, int out_len, char *out_dirname, int old[], unsigned int
nr = seqnr / 1000000000;
len = snprintf(out, out_len, "%s/%01u", out_dirname, nr);
len = scnprintf(out, out_len, "%s/%01u", out_dirname, nr);
if (old[0] != nr) {
old[0] = nr;
@ -150,7 +150,7 @@ int make_dirs(char *out, int out_len, char *out_dirname, int old[], unsigned int
nr = seqnr / 1000000 % 1000;
len += snprintf(out + len, out_len - len, "/%03u", nr);
len += scnprintf(out + len, out_len - len, "/%03u", nr);
if (old[1] != nr) {
old[1] = nr;
@ -159,7 +159,7 @@ int make_dirs(char *out, int out_len, char *out_dirname, int old[], unsigned int
nr = seqnr / 1000 % 1000;
len += snprintf(out + len, out_len - len, "/%03u", nr);
len += scnprintf(out + len, out_len - len, "/%03u", nr);
if (old[2] != nr) {
old[2] = nr;