Skip to content

Commit

Permalink
Attempt to safe gaurd int conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Mar 28, 2022
1 parent b116f98 commit 8608536
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion gqlgen/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package gqlgen

import (
"encoding/json"
"errors"
"fmt"
"io"
"math"
"strconv"

"github.com/99designs/gqlgen/graphql"
Expand Down Expand Up @@ -33,7 +35,10 @@ func UnmarshalInt16(v interface{}) (int16, error) {
if err != nil {
return 0, err
}
return int16(u64), err
if u64 <= math.MaxUint16 {
return int16(u64), err
}
return 0, errors.New("value is > math.MaxUint16")
default:
return 0, fmt.Errorf("%T is not an int16", v)
}
Expand Down
7 changes: 6 additions & 1 deletion gqlgen/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package gqlgen

import (
"encoding/json"
"errors"
"fmt"
"io"
"math"
"strconv"

"github.com/99designs/gqlgen/graphql"
Expand Down Expand Up @@ -31,7 +33,10 @@ func UnmarshalUint(v interface{}) (uint, error) {
if err != nil {
return 0, err
}
return uint(u64), err
if u64 <= math.MaxUint {
return uint(u64), err
}
return 0, errors.New("value is > math.MaxUint")
default:
return 0, fmt.Errorf("%T is not an uint", v)
}
Expand Down

0 comments on commit 8608536

Please sign in to comment.