Skip to content

pmrfc3164: accept IPv6 literals as HOSTNAME tokens#158

Open
rgerhards wants to merge 1 commit intomainfrom
codex/analyze-github-issue-#3012
Open

pmrfc3164: accept IPv6 literals as HOSTNAME tokens#158
rgerhards wants to merge 1 commit intomainfrom
codex/analyze-github-issue-#3012

Conversation

@rgerhards
Copy link
Owner

Motivation

  • The RFC3164 parser rejected IPv6 address literals in the HOSTNAME field, causing hostname parsing to fail and corrupt forwarded headers when sources send IPv6 addresses without DNS names.
  • The change aims to accept valid IPv6 literals (with optional square brackets) so TAG parsing stays aligned and forwarded messages keep correct syslog formatting.

Description

  • Added #include <arpa/inet.h> and a helper isIPv6HostnameToken that validates a candidate token as an IPv6 address using inet_pton and honors the permit.squarebracketsinhostname option.
  • Extended the hostname-parsing path in tools/pmrfc3164.c to, on normal-hostname rejection, scan the next token up to the next space and, if it contains a colon, validate and accept it as an IPv6 HOSTNAME token and advance the parse pointer accordingly.
  • Kept existing behavior for bracketed hostnames and plain hostnames, and preserved maximum hostname bounds (CONF_HOSTNAME_MAXSIZE).

Testing

  • Ran code formatting using ./devtools/format-code.sh, which completed successfully.
  • No automated parser or runtime tests were executed as part of this change (not requested).

Codex Task

@gemini-code-assist
Copy link

Summary of Changes

Hello @rgerhards, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the RFC3164 parser failed to recognize IPv6 address literals in the HOSTNAME field, leading to incorrect parsing and potentially corrupted syslog headers. By integrating robust IPv6 hostname detection and validation, the change ensures that syslog messages from IPv6-only environments are processed accurately, preserving the integrity and correct formatting of forwarded messages.

Highlights

  • IPv6 Hostname Support: The RFC3164 parser now correctly accepts IPv6 address literals as valid HOSTNAME tokens, preventing parsing failures and data corruption for syslog messages originating from IPv6 sources.
  • New IPv6 Validation Function: A helper function, isIPv6HostnameToken, has been introduced to validate potential IPv6 address tokens, including support for optional square brackets as per configuration.
  • Enhanced Hostname Parsing Logic: The parsing mechanism in tools/pmrfc3164.c has been extended to attempt IPv6 hostname parsing if the initial standard hostname validation fails, ensuring broader compatibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces support for parsing IPv6 address literals in the HOSTNAME field of RFC3164 messages, which is a valuable enhancement for handling modern network configurations. The new isIPv6HostnameToken helper function encapsulates the IPv6 validation logic well. However, a potential buffer overflow issue was identified in the isIPv6HostnameToken function related to the size checks for the addr_buf buffer, which should be addressed to ensure memory safety.

const uchar* addr_start = token;
size_t addr_len = token_len;

if (token_len == 0 || token_len >= sizeof(addr_buf)) {

Choose a reason for hiding this comment

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

high

The condition token_len >= sizeof(addr_buf) might lead to a buffer overflow. sizeof(addr_buf) is INET6_ADDRSTRLEN (46). If token_len is exactly 46, the subsequent addr_buf[addr_len] = '\0' on line 89 would write one byte past the end of the addr_buf array. The check should reserve space for the null terminator.

Consider changing this to token_len >= sizeof(addr_buf) - 1.

    if (token_len == 0 || token_len >= sizeof(addr_buf) - 1) {

}
addr_start = token + 1;
addr_len = token_len - 2;
if (addr_len == 0 || addr_len >= sizeof(addr_buf)) {

Choose a reason for hiding this comment

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

high

Similar to the previous comment, this condition addr_len >= sizeof(addr_buf) could also lead to a buffer overflow. If addr_len is exactly INET6_ADDRSTRLEN (46), the null terminator on line 89 would write out of bounds. This check should also reserve space for the null terminator.

Consider changing this to addr_len >= sizeof(addr_buf) - 1.

        if (addr_len == 0 || addr_len >= sizeof(addr_buf) - 1) {

Non-tech: IPv6 support in rfc3164 parsing so legacy pipelines keep
headers intact when devices send IPv6 addresses instead of DNS names.

Impact: user-visible bugfix; RFC3164 forwarding stays well-formed for
IPv6-only sources.

Before: an IPv6 literal in HOSTNAME broke parsing and misaligned the
forwarded header. After: valid IPv6 literals (optionally bracketed)
are accepted as HOSTNAME; TAG parsing remains in sync.

Technical: when normal hostname recognition fails, the parser scans
the next token up to space. If it contains a colon and validates via
inet_pton(AF_INET6), the token becomes HOSTNAME. Bracketed tokens are
accepted only when permit.squarebracketsinhostname is on. The parse
pointer advances past the token and any trailing space to preserve the
RFC3164 flow. Hostname size limits (CONF_HOSTNAME_MAXSIZE) remain.
A regression test (pmrfc3164-ipv6-hostname.sh) exercises both forms and
is added to tests/Makefile.am.

Fixes: rsyslog#3012

With the help of AI agents: Google Jules
@rgerhards rgerhards force-pushed the codex/analyze-github-issue-#3012 branch from 3f79004 to a08d7be Compare February 4, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant