Fix string-quoting checks. Was breaking team joining etc.

Unfortunately, our code has a mix of (source, dest[, length]) and (dest[,
length], source) in function prototypes. We need to fix this, or this kind
of problem is likely to occur again. My preference is for the latter, giving
consistency with the likes of the standard C library: least surprise and all
that.
Add two missing buffer validation checks for string quoting.