Fix printing non-terminated strings in devlist XML.

MFC after:	1 week
This commit is contained in:
Alexander Motin 2014-10-26 15:28:07 +00:00
parent b90638866e
commit fd86d88034
2 changed files with 9 additions and 5 deletions

View File

@ -2200,13 +2200,14 @@ ctl_copyout_args(int num_args, struct ctl_be_arg *args)
* Escape characters that are illegal or not recommended in XML.
*/
int
ctl_sbuf_printf_esc(struct sbuf *sb, char *str)
ctl_sbuf_printf_esc(struct sbuf *sb, char *str, int size)
{
char *end = str + size;
int retval;
retval = 0;
for (; *str; str++) {
for (; *str && str < end; str++) {
switch (*str) {
case '&':
retval = sbuf_printf(sb, "&amp;");
@ -3198,7 +3199,8 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
break;
retval = ctl_sbuf_printf_esc(sb,
lun->be_lun->serial_num);
lun->be_lun->serial_num,
sizeof(lun->be_lun->serial_num));
if (retval != 0)
break;
@ -3213,7 +3215,9 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
if (retval != 0)
break;
retval = ctl_sbuf_printf_esc(sb,lun->be_lun->device_id);
retval = ctl_sbuf_printf_esc(sb,
lun->be_lun->device_id,
sizeof(lun->be_lun->device_id));
if (retval != 0)
break;

View File

@ -156,7 +156,7 @@ int ctl_port_list(struct ctl_port_entry *entries, int num_entries_alloced,
* Put a string into an sbuf, escaping characters that are illegal or not
* recommended in XML. Note this doesn't escape everything, just > < and &.
*/
int ctl_sbuf_printf_esc(struct sbuf *sb, char *str);
int ctl_sbuf_printf_esc(struct sbuf *sb, char *str, int size);
int ctl_ffz(uint32_t *mask, uint32_t size);
int ctl_set_mask(uint32_t *mask, uint32_t bit);