mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Refine batch processing.
Try to remove possibility of stack smashing or infey loops. Add detection of CRLF formatted input files.
This commit is contained in:
parent
d6a733d517
commit
e2f35eaf39
@ -200,10 +200,15 @@ int batch_process(struct zint_symbol *symbol, char *filename)
|
|||||||
char adjusted[2];
|
char adjusted[2];
|
||||||
|
|
||||||
memset(buffer, 0, sizeof(unsigned char) * 7100);
|
memset(buffer, 0, sizeof(unsigned char) * 7100);
|
||||||
if(symbol->outfile[0] = '\0') {
|
if(symbol->outfile[0] == '\0') {
|
||||||
strcpy(format_string, "$$$$$.png");
|
strcpy(format_string, "$$$$$.png");
|
||||||
} else {
|
} else {
|
||||||
|
if(strlen(format_string) < 127) {
|
||||||
strcpy(format_string, symbol->outfile);
|
strcpy(format_string, symbol->outfile);
|
||||||
|
} else {
|
||||||
|
strcpy(symbol->errtxt, "Format string too long");
|
||||||
|
return ERROR_INVALID_DATA;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memset(adjusted, 0, sizeof(char) * 2);
|
memset(adjusted, 0, sizeof(char) * 2);
|
||||||
|
|
||||||
@ -220,6 +225,11 @@ int batch_process(struct zint_symbol *symbol, char *filename)
|
|||||||
do {
|
do {
|
||||||
character = fgetc(file);
|
character = fgetc(file);
|
||||||
if(character == '\n') {
|
if(character == '\n') {
|
||||||
|
if(buffer[posn - 1] == '\r') {
|
||||||
|
/* CR+LF - assume Windows formatting and remove CR */
|
||||||
|
posn--;
|
||||||
|
buffer[posn] = '\0';
|
||||||
|
}
|
||||||
inpos = 0;
|
inpos = 0;
|
||||||
local_line_count = line_count;
|
local_line_count = line_count;
|
||||||
memset(number, 0, sizeof(char) * 12);
|
memset(number, 0, sizeof(char) * 12);
|
||||||
@ -290,7 +300,17 @@ int batch_process(struct zint_symbol *symbol, char *filename)
|
|||||||
buffer[posn] = character;
|
buffer[posn] = character;
|
||||||
posn++;
|
posn++;
|
||||||
}
|
}
|
||||||
} while (!feof(file));
|
if(posn > 7090) {
|
||||||
|
fprintf(stderr, "On line %d: Input data too long\n", line_count);
|
||||||
|
do {
|
||||||
|
character = fgetc(file);
|
||||||
|
} while((!feof(file)) && (character != '\n'));
|
||||||
|
}
|
||||||
|
} while ((!feof(file)) && (line_count < 2000000000));
|
||||||
|
|
||||||
|
if(character != '\n') {
|
||||||
|
fprintf(stderr, "Warning: No newline at end of file\n");
|
||||||
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return error_number;
|
return error_number;
|
||||||
|
Loading…
Reference in New Issue
Block a user