Try to protect from malformed colours

This commit is contained in:
Robin Stuart 2019-03-18 17:36:36 +00:00
parent 32b6bbaf0e
commit b531abf9b4

View File

@ -40,6 +40,7 @@
#include "gs1.h" #include "gs1.h"
#define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" #define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
#define TITANIUM "01234567890ABCDEFabcdef"
struct zint_symbol *ZBarcode_Create() { struct zint_symbol *ZBarcode_Create() {
struct zint_symbol *symbol; struct zint_symbol *symbol;
@ -1129,6 +1130,20 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} }
//Check value of colours
if ((strlen(symbol->bgcolour) > 6) || (strlen(symbol->fgcolour) > 6)) {
strcpy(symbol->errtxt, "232: Invalid colour");
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
return ZINT_ERROR_INVALID_OPTION;
}
if ((is_sane(TITANIUM, (unsigned char *)symbol->bgcolour, strlen(symbol->bgcolour)) == ZINT_ERROR_INVALID_DATA)
|| (is_sane(TITANIUM, (unsigned char *)symbol->fgcolour, strlen(symbol->bgcolour)) == ZINT_ERROR_INVALID_DATA)) {
strcpy(symbol->errtxt, "233: Invalid characters in colour");
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
return ZINT_ERROR_INVALID_OPTION;
}
switch (symbol->symbology) { switch (symbol->symbology) {
case BARCODE_QRCODE: case BARCODE_QRCODE:
case BARCODE_MICROQR: case BARCODE_MICROQR: