summaryrefslogtreecommitdiff
path: root/fs/ubifs/debug.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-01-11 17:52:09 +0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-01-13 14:46:21 +0400
commitbeba006074e7170d3bc91470c8a6c914730d4c63 (patch)
tree3d7330a25a1c7c8228774ec9ff9cc7f1f2dcd1ab /fs/ubifs/debug.c
parentd34315da9146253351146140ea4b277193ee5e5f (diff)
downloadlinux-beba006074e7170d3bc91470c8a6c914730d4c63.tar.xz
UBIFS: use snprintf instead of sprintf when printing keys
Switch to 'snprintf()' which is more secure and reliable. This is also a preparation to the subsequent key printing fixes. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'fs/ubifs/debug.c')
-rw-r--r--fs/ubifs/debug.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index b09ba2dd8b62..6ae9fdcd2020 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -103,8 +103,8 @@ static const char *get_dent_type(int type)
}
}
-static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
- char *buffer)
+static void snprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
+ char *buffer, int len)
{
char *p = buffer;
int type = key_type(c, key);
@@ -112,44 +112,46 @@ static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) {
switch (type) {
case UBIFS_INO_KEY:
- sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key),
- get_key_type(type));
+ len -= snprintf(p, len, "(%lu, %s)",
+ (unsigned long)key_inum(c, key),
+ get_key_type(type));
break;
case UBIFS_DENT_KEY:
case UBIFS_XENT_KEY:
- sprintf(p, "(%lu, %s, %#08x)",
- (unsigned long)key_inum(c, key),
- get_key_type(type), key_hash(c, key));
+ len -= snprintf(p, len, "(%lu, %s, %#08x)",
+ (unsigned long)key_inum(c, key),
+ get_key_type(type), key_hash(c, key));
break;
case UBIFS_DATA_KEY:
- sprintf(p, "(%lu, %s, %u)",
- (unsigned long)key_inum(c, key),
- get_key_type(type), key_block(c, key));
+ len -= snprintf(p, len, "(%lu, %s, %u)",
+ (unsigned long)key_inum(c, key),
+ get_key_type(type), key_block(c, key));
break;
case UBIFS_TRUN_KEY:
- sprintf(p, "(%lu, %s)",
- (unsigned long)key_inum(c, key),
- get_key_type(type));
+ len -= snprintf(p, len, "(%lu, %s)",
+ (unsigned long)key_inum(c, key),
+ get_key_type(type));
break;
default:
- sprintf(p, "(bad key type: %#08x, %#08x)",
- key->u32[0], key->u32[1]);
+ len -= snprintf(p, len, "(bad key type: %#08x, %#08x)",
+ key->u32[0], key->u32[1]);
}
} else
- sprintf(p, "bad key format %d", c->key_fmt);
+ len -= snprintf(p, len, "bad key format %d", c->key_fmt);
+ ubifs_assert(len > 0);
}
const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key)
{
/* dbg_lock must be held */
- sprintf_key(c, key, dbg_key_buf0);
+ snprintf_key(c, key, dbg_key_buf0, sizeof(dbg_key_buf0) - 1);
return dbg_key_buf0;
}
const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key)
{
/* dbg_lock must be held */
- sprintf_key(c, key, dbg_key_buf1);
+ snprintf_key(c, key, dbg_key_buf1, sizeof(dbg_key_buf1) - 1);
return dbg_key_buf1;
}