Skip to content

Fix integer overflow when parsing CGI array indices - #1784

Open
JWWTSL wants to merge 1 commit into
OpenPrinting:masterfrom
JWWTSL:fix-cgi-atoi
Open

JWWTSL wants to merge 1 commit into
OpenPrinting:masterfrom
JWWTSL:fix-cgi-atoi

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

atoi() is used to parse the numeric suffix of CGI form field names into an
array index in cgi-bin/var.c. On values that exceed INT_MAX this is
undefined behavior, and the result cannot be reliably validated by the
subsequent range check in cgiSetArray().

Add a _cups_parse_index() helper that uses strtol(), resets and checks
errno for ERANGE, and validates the parsed value before converting it to
an index. Use it at the three sites that build array indices.

Changes

File Change
cgi-bin/var.c add _cups_parse_index(); replace 3 atoi(x)-1 index computations

Test Plan

  • Built with make (object compiles cleanly).
  • Helper logic unit-tested: normal / boundary (1, 100001, 100002) / overflow /
    non-numeric / negative / empty all return expected indices or -1.

Fixes #1748

atoi() has undefined behavior on out-of-range values. Parse the
numeric suffix of form field names with strtol(), validate errno
and the range, and return -1 on any invalid input instead.

Fixes OpenPrinting#1748

This branch has not been deployed

No deployments
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.

Potential integer overflow when using atoi() In cgi-bin/var.c

1 participant