Skip to contentSkip to conversation

fs/proc/array.c: set overflow flag in case of error

PATCH Superseded Andy Shevchenko 1 participant 1 message Sep 18, 2015 Proc filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/proc/array.c: set overflow flag in case of error

For now in task_name() we ignore the return code of string_escape_str() call. This is not good if buffer suddenly becomes not big enough. Do the proper error handling there.

---
 fs/proc/array.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/proc/array.c +4 -5
index f60f012..21d2d30 100644
@@ -91,18 +91,17 @@
 static inline void task_name(struct seq_file *m, struct task_struct *p)
 {
 	char *buf;
+	size_t size = seq_get_buf(m, &buf);
 	char tcomm[sizeof(p->comm)];
+	int ret;
 
 	get_task_comm(tcomm, p);
 
 	seq_puts(m, "Name:\t");
-	buf = m->buf + m->count;
 
-	/* Ignore error for now */
-	buf += string_escape_str(tcomm, buf, m->size - m->count,
-				 ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
+	ret = string_escape_str(tcomm, buf, size, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
+	seq_commit(m, ret < size ? ret : -1);
 
-	m->count = buf - m->buf;
 	seq_putc(m, '\n');
 }
 
Signature · 1 line
2.5.1