diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-01-11 08:52:09 -0500 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-01-13 05:46:21 -0500 |
commit | beba006074e7170d3bc91470c8a6c914730d4c63 (patch) | |
tree | 3d7330a25a1c7c8228774ec9ff9cc7f1f2dcd1ab /fs/ubifs | |
parent | d34315da9146253351146140ea4b277193ee5e5f (diff) |
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')
-rw-r--r-- | fs/ubifs/debug.c | 38 |
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) | |||
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, | 106 | static void snprintf_key(const struct ubifs_info *c, const union ubifs_key *key, |
107 | char *buffer) | 107 | char *buffer, int len) |
108 | { | 108 | { |
109 | char *p = buffer; | 109 | char *p = buffer; |
110 | int type = key_type(c, key); | 110 | int type = key_type(c, key); |
@@ -112,44 +112,46 @@ static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, | |||
112 | if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { | 112 | if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { |
113 | switch (type) { | 113 | switch (type) { |
114 | case UBIFS_INO_KEY: | 114 | case UBIFS_INO_KEY: |
115 | sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key), | 115 | len -= snprintf(p, len, "(%lu, %s)", |
116 | get_key_type(type)); | 116 | (unsigned long)key_inum(c, key), |
117 | get_key_type(type)); | ||
117 | break; | 118 | break; |
118 | case UBIFS_DENT_KEY: | 119 | case UBIFS_DENT_KEY: |
119 | case UBIFS_XENT_KEY: | 120 | case UBIFS_XENT_KEY: |
120 | sprintf(p, "(%lu, %s, %#08x)", | 121 | len -= snprintf(p, len, "(%lu, %s, %#08x)", |
121 | (unsigned long)key_inum(c, key), | 122 | (unsigned long)key_inum(c, key), |
122 | get_key_type(type), key_hash(c, key)); | 123 | get_key_type(type), key_hash(c, key)); |
123 | break; | 124 | break; |
124 | case UBIFS_DATA_KEY: | 125 | case UBIFS_DATA_KEY: |
125 | sprintf(p, "(%lu, %s, %u)", | 126 | len -= snprintf(p, len, "(%lu, %s, %u)", |
126 | (unsigned long)key_inum(c, key), | 127 | (unsigned long)key_inum(c, key), |
127 | get_key_type(type), key_block(c, key)); | 128 | get_key_type(type), key_block(c, key)); |
128 | break; | 129 | break; |
129 | case UBIFS_TRUN_KEY: | 130 | case UBIFS_TRUN_KEY: |
130 | sprintf(p, "(%lu, %s)", | 131 | len -= snprintf(p, len, "(%lu, %s)", |
131 | (unsigned long)key_inum(c, key), | 132 | (unsigned long)key_inum(c, key), |
132 | get_key_type(type)); | 133 | get_key_type(type)); |
133 | break; | 134 | break; |
134 | default: | 135 | default: |
135 | sprintf(p, "(bad key type: %#08x, %#08x)", | 136 | len -= snprintf(p, len, "(bad key type: %#08x, %#08x)", |
136 | key->u32[0], key->u32[1]); | 137 | key->u32[0], key->u32[1]); |
137 | } | 138 | } |
138 | } else | 139 | } else |
139 | sprintf(p, "bad key format %d", c->key_fmt); | 140 | len -= snprintf(p, len, "bad key format %d", c->key_fmt); |
141 | ubifs_assert(len > 0); | ||
140 | } | 142 | } |
141 | 143 | ||
142 | const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) | 144 | const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) |
143 | { | 145 | { |
144 | /* dbg_lock must be held */ | 146 | /* dbg_lock must be held */ |
145 | sprintf_key(c, key, dbg_key_buf0); | 147 | snprintf_key(c, key, dbg_key_buf0, sizeof(dbg_key_buf0) - 1); |
146 | return dbg_key_buf0; | 148 | return dbg_key_buf0; |
147 | } | 149 | } |
148 | 150 | ||
149 | const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) | 151 | const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) |
150 | { | 152 | { |
151 | /* dbg_lock must be held */ | 153 | /* dbg_lock must be held */ |
152 | sprintf_key(c, key, dbg_key_buf1); | 154 | snprintf_key(c, key, dbg_key_buf1, sizeof(dbg_key_buf1) - 1); |
153 | return dbg_key_buf1; | 155 | return dbg_key_buf1; |
154 | } | 156 | } |
155 | 157 | ||