mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 13:16:45 +00:00
QR code preventing crashes
This commit is contained in:
parent
3f4e79a195
commit
4d25e77ea6
@ -138,6 +138,11 @@ static const int PENALTY_N4 = 10;
|
|||||||
bool qrcodegen_encodeText(const char* text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl,
|
bool qrcodegen_encodeText(const char* text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl,
|
||||||
int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
|
int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
|
||||||
{
|
{
|
||||||
|
/* preventing crashes */
|
||||||
|
if (maxVersion > qrcodegen_VERSION_MAX_LIMIT) {
|
||||||
|
qrcode[0] = 0; // Set size to invalid value for safety
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
size_t textLen = strlen(text);
|
size_t textLen = strlen(text);
|
||||||
if(textLen == 0)
|
if(textLen == 0)
|
||||||
@ -172,6 +177,11 @@ fail:
|
|||||||
bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], enum qrcodegen_Ecc ecl,
|
bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], enum qrcodegen_Ecc ecl,
|
||||||
int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
|
int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
|
||||||
{
|
{
|
||||||
|
/* preventing crashes */
|
||||||
|
if (maxVersion > qrcodegen_VERSION_MAX_LIMIT) {
|
||||||
|
qrcode[0] = 0; // Set size to invalid value for safety
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
struct qrcodegen_Segment seg;
|
struct qrcodegen_Segment seg;
|
||||||
seg.mode = qrcodegen_Mode_BYTE;
|
seg.mode = qrcodegen_Mode_BYTE;
|
||||||
|
@ -132,12 +132,13 @@ struct qrcodegen_Segment
|
|||||||
* VERSION_MAX = 11 : max text length to encode 251 alphanumeric characters
|
* VERSION_MAX = 11 : max text length to encode 251 alphanumeric characters
|
||||||
* VERSION_MAX = 15 : max text length to encode 412 alphanumeric characters
|
* VERSION_MAX = 15 : max text length to encode 412 alphanumeric characters
|
||||||
* and so on
|
* and so on
|
||||||
* VERSION_MAX = 25 : openHASP restarts on qrcode update
|
* 25 is the highest posible version, see below
|
||||||
*/
|
*/
|
||||||
#define qrcodegen_VERSION_MIN 1 // The minimum version number
|
#define qrcodegen_VERSION_MIN 1 // The minimum version number
|
||||||
#ifndef qrcodegen_VERSION_MAX
|
#ifndef qrcodegen_VERSION_MAX
|
||||||
#define qrcodegen_VERSION_MAX 7 // The maximum version number
|
#define qrcodegen_VERSION_MAX 7 // The maximum version number
|
||||||
#endif
|
#endif
|
||||||
|
#define qrcodegen_VERSION_MAX_LIMIT 25
|
||||||
|
|
||||||
// Calculates the number of bytes needed to store any QR Code up to and including the given version number,
|
// Calculates the number of bytes needed to store any QR Code up to and including the given version number,
|
||||||
// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];'
|
// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user