Fix buffer overflow; call strdup only when 3-rd argument is missing