GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Silent Data Corruption via Unescaped Enum Values in Generated Go Code · Issue #4448 · sqlc-dev/sqlc Open Labels bugSomething isn't workingSomething isn't working DescriptionVersion1.31.1 What happened?Summarysqlc v1.31.1 and earlier versions generate Go string constants from PostgreSQL enum values without applying Go string escaping. Enum values containing backslash characters are reinterpreted as Go escape sequences, producing constants whose runtime values silently differ from the corresponding database values. Enum values containing double-quote characters produce Go string concatenation expressions that compile successfully but evaluate to incorrect values. Details:The Go code generation template at internal/codegen/golang/templates/template.tmpl interpolates enum values using: The This creates three verified impacts: Silent semantic corruption: PostgreSQL enum value user\nadmin (literal backslash + n) generates Go constant "user\nadmin" (newline character). The 12-byte DB value becomes a 10-byte Go constant. Comparisons silently fail. Build disruption: Enum values containing " cause go/format.Source() to reject the generated code, breaking sqlc generate. Constant value manipulation: Enum values like injected" + "arbitrary_go_code" + " produce valid Go string concatenation that compiles with a different value. Both SQL file parsing and database introspection (database.uri) paths are affected. schema.sql: query.sql: sqlc.yaml: Run sqlc generate. The generated go/models.go contains: Verification: String concatenation variant. schema.sql: Generated output: Compiles as Go string concatenation. Constant value differs from DB value. ImpactSilent data corruption in any Go application using sqlc with PostgreSQL enum types containing backslashes. Role checks, status comparisons, and other enum-based logic fail silently. In an authorization context, if user.Role == UserRoleUsernadmin never matches, potentially granting or denying access incorrectly. Fix:Replace "{{.Value}}" on template.tmpl line 95 with {{printf "%q" .Value}}. Go’s %q verb properly escapes backslashes, double quotes, and non-printable characters. Relevant log outputDatabase schemaSQL queriesConfigurationPlayground URLNo response What operating system are you using?macOS What database engines are you using?PostgreSQL What type of code are you generating?Go ActivityMetadataMetadataAssigneesLabelsbugSomething isn't workingSomething isn't working TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |