{"record":{"id":"6d20c310b938bcf4","repo":"ginuerzh/gost","slug":"quic-tlsconfig-is-nil","errorCode":null,"errorMessage":"quic: tlsconfig is nil","messagePattern":"quic: tlsconfig is nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"quic.go","lineNumber":342,"sourceCode":"\t}\n\n\tgcm, err := cipher.NewGCM(c)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tnonceSize := gcm.NonceSize()\n\tif len(data) < nonceSize {\n\t\treturn nil, errors.New(\"ciphertext too short\")\n\t}\n\n\tnonce, ciphertext := data[:nonceSize], data[nonceSize:]\n\treturn gcm.Open(nil, nonce, ciphertext, nil)\n}\n\nfunc tlsConfigQUICALPN(tlsConfig *tls.Config) *tls.Config {\n\tif tlsConfig == nil {\n\t\tpanic(\"quic: tlsconfig is nil\")\n\t}\n\ttlsConfigQUIC := tlsConfig.Clone()\n\ttlsConfigQUIC.NextProtos = []string{\"http/3\", \"quic/v1\"}\n\treturn tlsConfigQUIC\n}\n","sourceCodeStart":324,"sourceCodeEnd":348,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/quic.go#L324-L348","documentation":"tlsConfigQUICALPN clones the caller's *tls.Config and sets ALPN protocols (http/3, quic/v1) for QUIC transport; it panics immediately if the provided *tls.Config is nil. The library requires an explicit TLS configuration (certs, server name) before establishing a QUIC session or listener.","triggerScenarios":"Calling QUIC dial/initSession or QUICListener with a config whose TLS field is nil — e.g. constructing the client Config without a *tls.Config, or reusing a zero-value config struct.","commonSituations":"Copying a config struct and dropping the TLS pointer; forgetting to build tls.Config{ServerName, Certificates/RootCAs} when switching from a TCP transport to QUIC; loading config from file where a tls section is absent.","solutions":["Provide a non-nil *tls.Config with ServerName and credentials (Certificates for server, RootCAs/InsecureSkipVerify only for tests) before dialing/listening over QUIC","Check your config-construction code path for a missing tls assignment (zero-value struct passed through)","Add an explicit nil check/early return in your own setup code with a clear error instead of reaching the library panic","Load certificates from disk and verify they parse before handing the config to the library"],"exampleFix":"// before\ncfg := &ClientConfig{} // TLS == nil -> panic: quic: tlsconfig is nil\n// after\ncfg := &ClientConfig{\n    TLSConfig: &tls.Config{ServerName: \"example.com\", RootCAs: pool},\n}","handlingStrategy":"type-guard","validationCode":"func ensureTLSForQUIC(c *tls.Config) error {\n    if c == nil {\n        return errors.New(\"QUIC transport requires a non-nil *tls.Config (set ServerName and credentials)\")\n    }\n    return nil\n}\n// call before dial/listen: if err := ensureTLSForQUIC(cfg.TLSConfig); err != nil { return err }","typeGuard":"func hasTLSConfig(c *tls.Config) bool { return c != nil }","tryCatchPattern":"// recover from the library panic as a last resort\nfunc safeQUICListener(cfg *Config) (l net.Listener, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            if s, ok := r.(string); ok && strings.Contains(s, \"tlsconfig is nil\") {\n                err = errors.New(\"config.TLSConfig is nil — provide *tls.Config for QUIC\")\n                return\n            }\n            panic(r)\n        }\n    }()\n    return QUICListener(cfg)\n}","preventionTips":["Always populate the TLS field when constructing a config intended for QUIC transport","When copying config structs, remember *tls.Config is a pointer — nil propagates silently","Build tls.Config (ServerName + certs/RootCAs) right after loading application config, not at dial time","Add your own nil check with a clear error before handing config to the library","Since this is a panic, ensure top-level recover() middleware exists in server code"],"tags":["panic","quic","tls","nil-config"],"backgroundTag":"nil-tls-config","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}