fs/proc/array.c: set overflow flag in case of error
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Sat, 7 Nov 2015 00:30:03 +0000 (16:30 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 7 Nov 2015 01:50:42 +0000 (17:50 -0800)
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/array.c

index eed2050db9be9c7795acd2153f976d4742e2fe82..d73291f5f0fcbfb0cd2cff2bb1b628a72f754f6e 100644 (file)
 static inline void task_name(struct seq_file *m, struct task_struct *p)
 {
        char *buf;
+       size_t size;
        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\\");
+       size = seq_get_buf(m, &buf);
+       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');
 }