boulder icon indicating copy to clipboard operation
boulder copied to clipboard

Model.go : type mismatch between db and model

Open orangepizza opened this issue 5 months ago • 2 comments

I found multiple signed vs unsigned type mismatch (uint vs int) inside db keys and between db and model:

for example, but not limited to from table schema in test/db defines tinyint columns as signed and id is unsigned (as that's default),

CREATE TABLE `authz2` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `identifierType` tinyint(4) NOT NULL,
  `identifierValue` varchar(255) NOT NULL,
  `registrationID` bigint(20) NOT NULL,
  `status` tinyint(4) NOT NULL,
  `expires` datetime NOT NULL,
  `challenges` tinyint(4) NOT NULL,
  `attempted` tinyint(4) DEFAULT NULL,
  `attemptedAt` datetime DEFAULT NULL,
  `token` binary(32) NOT NULL,

but authzModel in model.go have using int64 for signed and tinyint columns are using uint8

type authzModel struct {
	ID               int64      `db:"id"`
	IdentifierType   uint8      `db:"identifierType"`
	IdentifierValue  string     `db:"identifierValue"`
	RegistrationID   int64      `db:"registrationID"`
	Status           uint8      `db:"status"`
	Expires          time.Time  `db:"expires"`
	Challenges       uint8      `db:"challenges"`
	Attempted        *uint8     `db:"attempted"`
	AttemptedAt      *time.Time `db:"attemptedAt"`
	Token            []byte     `db:"token"`
	ValidationError  []byte     `db:"validationError"`
	ValidationRecord []byte     `db:"validationRecord"`
}
  1. while in db authz and order id is unsigned at its own table, but in most other tables that have orderID using signed bigint at that. while it's unlikely to those uid to overflow.

While I don't think those fields will overflow anytime soon, (like most near one would be authz having 128 states or >128 challenge types), I think I'd better to notify this.

orangepizza avatar Jan 27 '24 02:01 orangepizza

Thank you very much for the sharp eye.

pgporada avatar Jan 29 '24 14:01 pgporada

Challenges field was actually bitmap, so it'll blow up at 8th challenge type actually. this currently have 3 types and 2 more if we start adding other types : onion-csr and dns-account-01 (think http-01 and tls-alpn for IP types are same enough)

orangepizza avatar Jan 29 '24 19:01 orangepizza