The usage of xorm get has risk #5562

Closed
opened 2025-11-02 06:29:04 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @yuyuanshifu on GitHub (Jun 17, 2020).

Description

Such as the usage of xorm get in models/attachment.go, if the id or uuid is empty, the query sql will be no where: select ... from attachment limit 1. The query will not be an error, but the query result could be not the result you want.
I suppose we use xorm get by this way:
attach := new(Attachment)
has, err := engine.Where("id=?", id).Get(attach)

Screenshots

image

Originally created by @yuyuanshifu on GitHub (Jun 17, 2020). ## Description Such as the usage of xorm get in models/attachment.go, if the id or uuid is empty, the query sql will be no where: select ... from attachment limit 1. The query will not be an error, but the query result could be not the result you want. I suppose we use xorm get by this way: attach := new(Attachment) has, err := engine.Where("id=?", id).Get(attach) ## Screenshots ![image](https://user-images.githubusercontent.com/7686122/84849538-186c1a00-b088-11ea-8a3b-0ab14b1d5075.png) <!-- **If this issue involves the Web Interface, please include a screenshot** -->
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5562