From e81a90bb589338508aeb172a3885b04d03d8ffc6 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Wed, 26 Jul 2017 11:44:47 +0100 Subject: [PATCH] Avoid SIGSEGV on Code 128 input too long --- backend/library.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/library.c b/backend/library.c index 00c973ea..32789c4d 100644 --- a/backend/library.c +++ b/backend/library.c @@ -809,7 +809,7 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour case BARCODE_CODABLOCKF: error_number = codablock(symbol, preprocessed, in_length); break; } - + return error_number; } @@ -1060,18 +1060,16 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int } - if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { - for (i = 0; i < in_length; i++) { - if (local_source[i] == '\0') { - symbol->text[i] = ' '; - } else { - symbol->text[i] = local_source[i]; + if (error_number == 0) { + if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { + for (i = 0; i < in_length; i++) { + if (local_source[i] == '\0') { + symbol->text[i] = ' '; + } else { + symbol->text[i] = local_source[i]; + } } } - } - - if (error_number == 0) { - error_number = error_buffer; } error_tag(symbol->errtxt, error_number);