Implement BUF_strnlen() and use it instead of strlen().