Merge pull request #4430 from lkrishnamoor/hostname_crash

lib: crash when FRR hostname length > 80 chars
This commit is contained in:
Donald Sharp 2019-05-31 15:02:10 -04:00 committed by GitHub
commit ce231fbc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 4 deletions

View File

@ -1962,7 +1962,15 @@ DEFUN (config_hostname,
struct cmd_token *word = argv[1]; struct cmd_token *word = argv[1];
if (!isalnum((int)word->arg[0])) { if (!isalnum((int)word->arg[0])) {
vty_out(vty, "Please specify string starting with alphabet\n"); vty_out(vty,
"Please specify string starting with alphabet or number\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* With reference to RFC 1123 Section 2.1 */
if (strlen(word->arg) > HOSTNAME_LEN) {
vty_out(vty, "Hostname length should be less than %d chars\n",
HOSTNAME_LEN);
return CMD_WARNING_CONFIG_FAILED; return CMD_WARNING_CONFIG_FAILED;
} }

View File

@ -37,6 +37,17 @@ extern "C" {
DECLARE_MTYPE(HOST) DECLARE_MTYPE(HOST)
DECLARE_MTYPE(COMPLETION) DECLARE_MTYPE(COMPLETION)
/*
* From RFC 1123 (Requirements for Internet Hosts), Section 2.1 on hostnames:
* One aspect of host name syntax is hereby changed: the restriction on
* the first character is relaxed to allow either a letter or a digit.
* Host software MUST support this more liberal syntax.
*
* Host software MUST handle host names of up to 63 characters and
* SHOULD handle host names of up to 255 characters.
*/
#define HOSTNAME_LEN 255
/* Host configuration variable */ /* Host configuration variable */
struct host { struct host {
/* Host name of this router. */ /* Host name of this router. */

View File

@ -3438,7 +3438,7 @@ void vtysh_readline_init(void)
char *vtysh_prompt(void) char *vtysh_prompt(void)
{ {
static char buf[100]; static char buf[512];
snprintf(buf, sizeof buf, cmd_prompt(vty->node), cmd_hostname_get()); snprintf(buf, sizeof buf, cmd_prompt(vty->node), cmd_hostname_get());
return buf; return buf;

View File

@ -521,10 +521,10 @@ int vtysh_read_config(const char *config_default_dir)
*/ */
void vtysh_config_write(void) void vtysh_config_write(void)
{ {
char line[81]; char line[512];
if (cmd_hostname_get()) { if (cmd_hostname_get()) {
sprintf(line, "hostname %s", cmd_hostname_get()); snprintf(line, sizeof(line), "hostname %s", cmd_hostname_get());
vtysh_config_parse_line(NULL, line); vtysh_config_parse_line(NULL, line);
} }