Skip to content

crypto/x509: when TestEnvVars fails, it "index out of range" panics due to off-by-one bug #20801

Description

@dmitshur

I already reported the issue in the CL where it was introduced. /cc @stevenh @bradfitz Creating this issue for posterity, so I can reference it in the CL I'm about to send.

TestEnvVars contains this code:

for i, cn := range tc.cns {
	if i > len(r.certs) {
		t.Errorf("missing cert %v @ %v", cn, i)
	} else if r.certs[i].Subject.CommonName != cn {
		// ...
	}
}

It should have i >= len(r.certs) instead, otherwise r.certs[i] in the else if will panic when i == len(r.certs).

This panic happens when the test fails due to the returned number of certificates (r.certs) being less than expected by test case (tc.cns).

CL upcoming. Edit: Sent CL 46715.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions