librb: linebuf needs to use the buffer limit from msgbuf_unparse_prefix

This commit is contained in:
Simon Arlott 2017-07-29 23:32:27 +01:00
parent 5ce6360b72
commit 4c7d1de8f3
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24
3 changed files with 7 additions and 4 deletions

View file

@ -223,7 +223,7 @@ linebuf_put_msgvbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int cap
rb_linebuf_newbuf(linebuf);
msgbuf_unparse_prefix(buf, &buflen, msgbuf, capmask);
rb_linebuf_putprefix(linebuf, pattern, va, buf);
rb_linebuf_putprefix(linebuf, pattern, va, buf, buflen);
}
/* linebuf_put_msgbuf

View file

@ -73,7 +73,7 @@ void rb_linebuf_donebuf(buf_head_t *);
int rb_linebuf_parse(buf_head_t *, char *, int, int);
int rb_linebuf_get(buf_head_t *, char *, int, int, int);
void rb_linebuf_putmsg(buf_head_t *, const char *, va_list *, const char *, ...);
void rb_linebuf_putprefix(buf_head_t *, const char *, va_list *, const char *);
void rb_linebuf_putprefix(buf_head_t *, const char *, va_list *, const char *, size_t);
void rb_linebuf_put(buf_head_t *, const char *, ...);
void rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer);
void rb_linebuf_attach(buf_head_t *, buf_head_t *);

View file

@ -561,10 +561,11 @@ rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args,
* Similar to rb_linebuf_put, but designed for use by send.c.
*
* prefix is inserted first, then format/va_args is appended to the buffer.
* prefix_buflen is the maximum size of the buffer that can be used so that the RFC1459 message is not too long
*/
void
rb_linebuf_putprefix(buf_head_t * bufhead, const char *format, va_list * va_args,
const char *prefix)
const char *prefix, size_t prefix_buflen)
{
buf_line_t *bufline;
int len = 0;
@ -584,7 +585,9 @@ rb_linebuf_putprefix(buf_head_t * bufhead, const char *format, va_list * va_args
if(va_args != NULL)
{
len += vsnprintf((bufline->buf + len), (LINEBUF_DATA_SIZE - len) + 1, format, *va_args);
if (prefix_buflen > LINEBUF_DATA_SIZE + 1)
prefix_buflen = LINEBUF_DATA_SIZE + 1;
len += vsnprintf((bufline->buf + len), prefix_buflen - len, format, *va_args);
}
bufline->terminated = 1;