Skip to content

zebra: Validate SRv6 locator name length in VTY commands#21905

Open
cscarpitta wants to merge 1 commit into
FRRouting:masterfrom
cscarpitta:fix_srv6_locator_name_len
Open

zebra: Validate SRv6 locator name length in VTY commands#21905
cscarpitta wants to merge 1 commit into
FRRouting:masterfrom
cscarpitta:fix_srv6_locator_name_len

Conversation

@cscarpitta
Copy link
Copy Markdown
Contributor

Currently, when a user configures an SRv6 locator with a name exceeding SRV6_LOCNAME_SIZE (255 characters), the 'locator' command passes the full input to srv6_locator_alloc(), which silently truncates the name via strlcpy() into the fixed-size name buffer. This results in the allocated locator having a different name than the user requested

Add explicit input validation to reject names exceeding the maximum length in both locator (create) and no locator (delete) VTY commands, ensuring the stored locator name matches user intent.

Currently, when a user configures an SRv6 locator with a name exceeding
SRV6_LOCNAME_SIZE (255 characters), the 'locator' command passes the full
input to srv6_locator_alloc(), which silently truncates the name via
strlcpy() into the fixed-size name buffer. This results in the allocated
locator having a different name than the user requested

Add explicit input validation to reject names exceeding the maximum length
in both 'locator' (create) and 'no locator' (delete) VTY commands, ensuring
the stored locator name matches user intent.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 8, 2026

Greptile Summary

This PR adds explicit input validation to reject SRv6 locator names that meet or exceed SRV6_LOCNAME_SIZE (256) characters in both the locator (create) and no locator (delete) VTY commands, preventing the silent truncation that previously occurred inside srv6_locator_alloc() via strlcpy.

  • Adds a strlen >= SRV6_LOCNAME_SIZE guard in srv6_locator before the lookup/alloc path, with a clear error message reporting the maximum allowed length (255 characters).
  • Adds the same guard in no_srv6_locator, moving the locator variable declaration to before the check; the boundary condition (>= SRV6_LOCNAME_SIZE) is correct for a 256-byte null-terminated buffer.

Confidence Score: 4/5

The change is narrowly scoped to input validation in two VTY command handlers and does not touch any data structures, allocation logic, or client notification paths.

The boundary check (>= SRV6_LOCNAME_SIZE) is correct for a 256-byte buffer and the error message accurately reports 255 as the maximum. The only notes are two %u format specifiers used with an int expression that could produce -Wformat warnings under strict compiler settings.

No files require special attention beyond the two format-specifier suggestions in zebra/zebra_srv6_vty.c.

Important Files Changed

Filename Overview
zebra/zebra_srv6_vty.c Adds explicit length validation (>= SRV6_LOCNAME_SIZE) for locator names in both srv6_locator (create) and no_srv6_locator (delete) VTY commands; logic and boundary are correct, minor format-specifier mismatch (%u vs int).
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
zebra/zebra_srv6_vty.c:804-808
The `%u` format specifier expects an `unsigned int`, but `SRV6_LOCNAME_SIZE - 1` is an `int` (the macro expands to the integer literal `256`). While benign for this value, it can trigger a `-Wformat` compiler warning. Using `%d` matches the actual type.

```suggestion
	if (strlen(argv[1]->arg) >= SRV6_LOCNAME_SIZE) {
		vty_out(vty, "%% Invalid locator name: maximum length is %d characters\n",
			SRV6_LOCNAME_SIZE - 1);
		return CMD_WARNING_CONFIG_FAILED;
	}
```

### Issue 2 of 2
zebra/zebra_srv6_vty.c:838-842
Same `%u` vs `int` mismatch as in the `locator` command above — use `%d` to match the type of `SRV6_LOCNAME_SIZE - 1`.

```suggestion
	if (strlen(argv[2]->arg) >= SRV6_LOCNAME_SIZE) {
		vty_out(vty, "%% Invalid locator name: maximum length is %d characters\n",
			SRV6_LOCNAME_SIZE - 1);
		return CMD_WARNING_CONFIG_FAILED;
	}
```

Reviews (1): Last reviewed commit: "zebra: Validate SRv6 locator name length..." | Re-trigger Greptile

Comment thread zebra/zebra_srv6_vty.c
Comment on lines +804 to +808
if (strlen(argv[1]->arg) >= SRV6_LOCNAME_SIZE) {
vty_out(vty, "%% Invalid locator name: maximum length is %u characters\n",
SRV6_LOCNAME_SIZE - 1);
return CMD_WARNING_CONFIG_FAILED;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The %u format specifier expects an unsigned int, but SRV6_LOCNAME_SIZE - 1 is an int (the macro expands to the integer literal 256). While benign for this value, it can trigger a -Wformat compiler warning. Using %d matches the actual type.

Suggested change
if (strlen(argv[1]->arg) >= SRV6_LOCNAME_SIZE) {
vty_out(vty, "%% Invalid locator name: maximum length is %u characters\n",
SRV6_LOCNAME_SIZE - 1);
return CMD_WARNING_CONFIG_FAILED;
}
if (strlen(argv[1]->arg) >= SRV6_LOCNAME_SIZE) {
vty_out(vty, "%% Invalid locator name: maximum length is %d characters\n",
SRV6_LOCNAME_SIZE - 1);
return CMD_WARNING_CONFIG_FAILED;
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: zebra/zebra_srv6_vty.c
Line: 804-808

Comment:
The `%u` format specifier expects an `unsigned int`, but `SRV6_LOCNAME_SIZE - 1` is an `int` (the macro expands to the integer literal `256`). While benign for this value, it can trigger a `-Wformat` compiler warning. Using `%d` matches the actual type.

```suggestion
	if (strlen(argv[1]->arg) >= SRV6_LOCNAME_SIZE) {
		vty_out(vty, "%% Invalid locator name: maximum length is %d characters\n",
			SRV6_LOCNAME_SIZE - 1);
		return CMD_WARNING_CONFIG_FAILED;
	}
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread zebra/zebra_srv6_vty.c
Comment on lines +838 to +842
if (strlen(argv[2]->arg) >= SRV6_LOCNAME_SIZE) {
vty_out(vty, "%% Invalid locator name: maximum length is %u characters\n",
SRV6_LOCNAME_SIZE - 1);
return CMD_WARNING_CONFIG_FAILED;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Same %u vs int mismatch as in the locator command above — use %d to match the type of SRV6_LOCNAME_SIZE - 1.

Suggested change
if (strlen(argv[2]->arg) >= SRV6_LOCNAME_SIZE) {
vty_out(vty, "%% Invalid locator name: maximum length is %u characters\n",
SRV6_LOCNAME_SIZE - 1);
return CMD_WARNING_CONFIG_FAILED;
}
if (strlen(argv[2]->arg) >= SRV6_LOCNAME_SIZE) {
vty_out(vty, "%% Invalid locator name: maximum length is %d characters\n",
SRV6_LOCNAME_SIZE - 1);
return CMD_WARNING_CONFIG_FAILED;
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: zebra/zebra_srv6_vty.c
Line: 838-842

Comment:
Same `%u` vs `int` mismatch as in the `locator` command above — use `%d` to match the type of `SRV6_LOCNAME_SIZE - 1`.

```suggestion
	if (strlen(argv[2]->arg) >= SRV6_LOCNAME_SIZE) {
		vty_out(vty, "%% Invalid locator name: maximum length is %d characters\n",
			SRV6_LOCNAME_SIZE - 1);
		return CMD_WARNING_CONFIG_FAILED;
	}
```

How can I resolve this? If you propose a fix, please make it concise.

@donaldsharp
Copy link
Copy Markdown
Member

shouldn't this require yang model changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants