Allow large lines output by swid_generator to be processed

This commit is contained in:
Andreas Steffen
2014-05-31 21:25:47 +02:00
parent 3d4818bf18
commit 7a6d2f2bce
+13 -5
View File
@@ -60,11 +60,13 @@ static status_t read_swid_tags(private_swid_inventory_t *this, FILE *file)
swid_tag_t *tag; swid_tag_t *tag;
bio_writer_t *writer; bio_writer_t *writer;
chunk_t tag_encoding, tag_file_path = chunk_empty; chunk_t tag_encoding, tag_file_path = chunk_empty;
bool more_tags = TRUE, end_of_tag; bool more_tags = TRUE, last_newline, end_of_tag;
char line[131072]; char line[8192];
size_t len;
while (more_tags) while (more_tags)
{ {
last_newline = TRUE;
end_of_tag = FALSE; end_of_tag = FALSE;
writer = bio_writer_create(512); writer = bio_writer_create(512);
do do
@@ -75,14 +77,17 @@ static status_t read_swid_tags(private_swid_inventory_t *this, FILE *file)
end_of_tag = TRUE; end_of_tag = TRUE;
break; break;
} }
if (line[0] == '\n') len = strlen(line);
if (last_newline && line[0] == '\n')
{ {
end_of_tag = TRUE; end_of_tag = TRUE;
break; break;
} }
else else
{ {
writer->write_data(writer, chunk_from_str(line)); last_newline = (line[len-1] == '\n');
writer->write_data(writer, chunk_create(line, len));
} }
} }
while (!end_of_tag); while (!end_of_tag);
@@ -155,6 +160,8 @@ static status_t generate_tags(private_swid_inventory_t *this, char *generator,
FILE *file; FILE *file;
char command[BUF_LEN]; char command[BUF_LEN];
char entity_name[] = "strongSwan Project"; char entity_name[] = "strongSwan Project";
char doc_separator[] = "'\n\n'";
status_t status = SUCCESS; status_t status = SUCCESS;
if (targets->get_count(targets) == 0) if (targets->get_count(targets) == 0)
@@ -163,7 +170,8 @@ static status_t generate_tags(private_swid_inventory_t *this, char *generator,
if (this->full_tags) if (this->full_tags)
{ {
snprintf(command, BUF_LEN, "%s swid --entity-name \"%s\" " snprintf(command, BUF_LEN, "%s swid --entity-name \"%s\" "
"--doc-separator $'\n\n'%s%s", generator, entity_name, "--doc-separator %s%s%s",
generator, entity_name, doc_separator,
pretty ? " --pretty" : "", full ? " --full" : ""); pretty ? " --pretty" : "", full ? " --full" : "");
} }
else else