Skip to content

Fix FLARE_OPERATOR_PORT parsing: replace atoi with strtol + range validation#141

Draft
Copilot wants to merge 3 commits intoflare-operatorfrom
copilot/sub-pr-140
Draft

Fix FLARE_OPERATOR_PORT parsing: replace atoi with strtol + range validation#141
Copilot wants to merge 3 commits intoflare-operatorfrom
copilot/sub-pr-140

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 15, 2026

FLARE_OPERATOR_PORT was parsed with atoi, which silently returns 0 on invalid input and has no range validation — allowing an invalid port to reach index_server_port without any diagnostic.

Changes

  • src/flared/flared.cc
    • Replace atoi with strtol + full error detection (errno, endptr, trailing-char check)
    • Validate parsed port is in range [1, 65535]; emit log_warning and skip override on invalid input
    • Parse once into port_val; reuse static_cast<int>(port_val) for both s.index_server_port and the log_notice line
    • Add <cerrno> to the ENABLE_K8S_OPERATOR include guard
char* endptr = nullptr;
errno = 0;
long port_val = strtol(op_port, &endptr, 10);
if (errno != 0 || endptr == op_port || *endptr != '\0' || port_val < 1 || port_val > 65535) {
    log_warning("K8s operator mode: invalid FLARE_OPERATOR_PORT value '%s', ignoring operator override", op_port);
} else {
    k8s_index_servers.clear();
    cluster::index_server s;
    s.index_server_name = string(op_host);
    s.index_server_port = static_cast<int>(port_val);
    k8s_index_servers.push_back(s);
    log_notice("K8s operator mode: using operator at %s:%d as index server",
        op_host, static_cast<int>(port_val));
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

junjihashimoto and others added 2 commits March 16, 2026 08:32
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: junjihashimoto <2469618+junjihashimoto@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on the Flare operator pull request Fix FLARE_OPERATOR_PORT parsing: replace atoi with strtol + range validation Mar 15, 2026
Copilot AI requested a review from junjihashimoto March 15, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants