aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
103 } 103 }
104} 104}
105 105
106static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, 106static 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
142const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) 144const 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
149const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) 151const 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