Always copying passed options to protect callback data integrity.

pull/111/head
Ian Byrd 7 years ago
parent 426f436905
commit b831116da3
No known key found for this signature in database
GPG Key ID: 598F598CA3B8055F

@ -46,6 +46,15 @@ type SendOptions struct {
ParseMode ParseMode
}
func (og *SendOptions) copy() *SendOptions {
cp := *og
if cp.ReplyMarkup != nil {
cp.ReplyMarkup = cp.ReplyMarkup.copy()
}
return &cp
}
// ReplyMarkup controls two convenient options for bot-user communications
// such as reply keyboard and inline "keyboard" (a grid of buttons as a part
// of the message).
@ -87,6 +96,28 @@ type ReplyMarkup struct {
Selective bool `json:"selective,omitempty"`
}
func (og *ReplyMarkup) copy() *ReplyMarkup {
cp := *og
cp.ReplyKeyboard = make([][]ReplyButton, len(og.ReplyKeyboard))
for i, row := range og.ReplyKeyboard {
cp.ReplyKeyboard[i] = make([]ReplyButton, len(row))
for j, btn := range row {
cp.ReplyKeyboard[i][j] = btn
}
}
cp.InlineKeyboard = make([][]InlineButton, len(og.InlineKeyboard))
for i, row := range og.InlineKeyboard {
cp.InlineKeyboard[i] = make([]InlineButton, len(row))
for j, btn := range row {
cp.InlineKeyboard[i][j] = btn
}
}
return &cp
}
// ReplyButton represents a button displayed in reply-keyboard.
//
// Set either Contact or Location to true in order to request

@ -96,13 +96,13 @@ func extractOptions(how []interface{}) *SendOptions {
for _, prop := range how {
switch opt := prop.(type) {
case *SendOptions:
opts = opt
opts = opt.copy()
case *ReplyMarkup:
if opts == nil {
opts = &SendOptions{}
}
opts.ReplyMarkup = opt
opts.ReplyMarkup = opt.copy()
case Option:
if opts == nil {

Loading…
Cancel
Save