Commit d2134dd
committed
bluetooth: fast_pair: fix Additional Data write length validation
Reworked the write_additional_data() GATT callback in the
fp_gatt_service module to validate the ATT write payload length
before deriving the decoded data length from it.
Previously, the function computed the decoded data length as
len - FP_CRYPTO_ADDITIONAL_DATA_HEADER_LEN and used the result as
the size of a stack-allocated variable-length array, without first
checking that len is at least equal to the header length. A short
write would underflow the unsigned subtraction, and a long write
could exceed the available stack budget.
Replaced the variable-length array with a fixed-size buffer of
FP_STORAGE_PN_BUF_LEN bytes, sized to the worst-case Personalized
Name plus the NULL terminator, and added explicit length checks:
- Rejected writes whose length is less than or equal to the
Additional Data header length with the
BT_ATT_ERR_INVALID_ATTRIBUTE_LEN ATT error.
- Rejected writes that would not fit in the decoded_data buffer
with the BT_ATT_ERR_INSUFFICIENT_RESOURCES ATT error, and
emitted a warning that points to the
CONFIG_BT_FAST_PAIR_STORAGE_PN_LEN_MAX Kconfig option for
longer Personalized Name support.
Ref: NCSDK-39121
Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>1 parent 980bcd2 commit d2134dd
1 file changed
Lines changed: 26 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
787 | 791 | | |
788 | | - | |
789 | | - | |
| 792 | + | |
| 793 | + | |
790 | 794 | | |
791 | 795 | | |
792 | 796 | | |
| |||
807 | 811 | | |
808 | 812 | | |
809 | 813 | | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
810 | 833 | | |
811 | 834 | | |
812 | 835 | | |
| |||
815 | 838 | | |
816 | 839 | | |
817 | 840 | | |
| 841 | + | |
818 | 842 | | |
819 | 843 | | |
820 | 844 | | |
| |||
0 commit comments