Index: sys/kern/subr_bus.c =================================================================== --- sys/kern/subr_bus.c +++ sys/kern/subr_bus.c @@ -878,6 +878,30 @@ } } +/** + * @brief safely quotes strings that might have double quotes in them. + * + * The devctl protocol relies on quoted strings having matching quotes. + * This routine quotes any internal quotes so the resulting string + * is safe to pass to snprintf to construct, for example pnp info strings. + * + * @param sb sbuf to place the characters into + * @param src Original buffer. + * @param len Max length of the buffer to process. + */ +void +devctl_safe_quote_sb_len(struct sbuf *sb, const char *src, size_t len) +{ + const char *srcp; + + srcp = src; + while (*srcp != '\0' && (srcp - src) < len) { + if (*srcp == '"' || *srcp == '\\') + sbuf_putc(sb, '\\'); + sbuf_putc(sb, *srcp++); + } +} + /* End of /dev/devctl code */ static struct device_list bus_data_devices; Index: sys/sys/devctl.h =================================================================== --- sys/sys/devctl.h +++ sys/sys/devctl.h @@ -19,6 +19,7 @@ const char *__type, const char *__data); struct sbuf; void devctl_safe_quote_sb(struct sbuf *__sb, const char *__src); +void devctl_safe_quote_sb_len(struct sbuf *sb, const char *src, size_t len); #endif #endif /* _SYS_DEVCTL_H_ */