diff options
Diffstat (limited to 'lib/seq_buf.c')
| -rw-r--r-- | lib/seq_buf.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/seq_buf.c b/lib/seq_buf.c index a92093f346da..54b76044e4ba 100644 --- a/lib/seq_buf.c +++ b/lib/seq_buf.c @@ -76,6 +76,8 @@ int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args) s->len += len; return 0; } + /* vsnprintf() wrote as much as fits, so none of it is stale */ + s->len = s->size; } seq_buf_set_overflow(s); return -1; @@ -128,7 +130,7 @@ void seq_buf_do_printk(struct seq_buf *s, const char *lvl) } /* No trailing LF */ - if (start < s->buffer + s->len) + if (*start) printk("%s%s\n", lvl, start); } EXPORT_SYMBOL_GPL(seq_buf_do_printk); @@ -164,6 +166,8 @@ int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary) s->len += ret; return 0; } + /* bstr_printf() wrote as much as fits, so none of it is stale */ + s->len = s->size; } seq_buf_set_overflow(s); return -1; @@ -175,7 +179,9 @@ int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary) * @s: seq_buf descriptor * @str: simple string to record * - * Copy a simple string into the sequence buffer. + * Copy a simple string into the sequence buffer. If @str does not fit, + * as much of it as fits is copied, followed by a null byte, as + * seq_buf_printf() does. * * Returns: zero on success, -1 on overflow. */ @@ -194,6 +200,11 @@ int seq_buf_puts(struct seq_buf *s, const char *str) s->len += len - 1; return 0; } + /* Copy what fits, so the buffer never holds stale bytes */ + if (s->len < s->size) { + strscpy(s->buffer + s->len, str, s->size - s->len); + s->len = s->size; + } seq_buf_set_overflow(s); return -1; } @@ -229,7 +240,7 @@ EXPORT_SYMBOL_GPL(seq_buf_putc); * * There may be cases where raw memory needs to be written into the * buffer and a strcpy() would not work. Using this function allows - * for such cases. + * for such cases. If @mem does not fit, as much of it as fits is copied. * * Returns: zero on success, -1 on overflow. */ @@ -242,9 +253,15 @@ int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len) s->len += len; return 0; } + /* Copy what fits, so the buffer never holds stale bytes */ + if (s->len < s->size) { + memcpy(s->buffer + s->len, mem, s->size - s->len); + s->len = s->size; + } seq_buf_set_overflow(s); return -1; } +EXPORT_SYMBOL_GPL(seq_buf_putmem); #define MAX_MEMHEX_BYTES 8U #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) @@ -330,6 +347,7 @@ int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc) return res; } +EXPORT_SYMBOL_GPL(seq_buf_path); /** * seq_buf_to_user - copy the sequence buffer to user space @@ -391,12 +409,13 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, size_t start, int cnt) * * Function is an analogue of print_hex_dump() and thus has similar interface. * - * linebuf size is maximal length for one line. - * 32 * 3 - maximum bytes per line, each printed into 2 chars + 1 for - * separating space - * 2 - spaces separating hex dump and ASCII representation - * 32 - ASCII representation - * 1 - terminating '\0' + * linebuf size is maximal length for one line:: + * + * 32 * 3 - maximum bytes per line, each printed into 2 chars + 1 for + * separating space + * 2 - spaces separating hex dump and ASCII representation + * 32 - ASCII representation + * 1 - terminating '\0' * * Returns: zero on success, -1 on overflow. */ |
