Prevent several buffer overflows.

cgi/cmd.c:cmd_submitf() was not checking that the formatted command
string would fit in MAX_EXTERNAL_COMMAND_LENGTH bytes. It is now
considered an error if the full command can not be formatted into a
buffer of this size.

lib/nsock.c:nsock_vprintf() failed to check for vsnprintf() overflow.
Since this is used as library code in several places (with unrigorous
checks for error), an attempt is made to complete the operation using
vasprintf(). Although slower, the penalty is mostly paid in cases that
would have likely segfaulted in the past. The implementation of this
also depends on having va_copy() available and working.

lib/worker.c:wlog() and job_error() had similar vsnprintf() issues. In
these cases the truncated messages are null-terminated and sent, with
the reasoning that the buffers used are relatively large (8K and 4K,
respectively) and a truncated log message is better than none at all.

Discovered-by: Aman Gupta
Reported-by: Dirkjan Bussink