# HG changeset patch # User Andre Heinecke # Date 1395656035 0 # Node ID 898446d9d23e9d13c41f764ea1a4abe0d79e044e # Parent 24fb90ef8f6af222d460de47a3face7d219f0cac Normalize input if neccessary diff -r 24fb90ef8f6a -r 898446d9d23e cinst/main.c --- a/cinst/main.c Mon Mar 24 10:13:13 2014 +0000 +++ b/cinst/main.c Mon Mar 24 10:13:55 2014 +0000 @@ -85,7 +85,7 @@ int lines_read = 0; int readingList = 0; size_t list_size = 0; - char buf[MAX_LINE_LENGTH + 1]; + char buf[MAX_LINE_LENGTH + 2]; if (*certificate_list || *to_install || *to_remove) { printf("Error invalid parameters\n"); @@ -94,14 +94,26 @@ while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { size_t len = strlen(buf); /* fgets ensures buf is terminated */ - if (len < 2) { - printf("Line to short.\n"); + if (len <= 3) { + printf("Line too short.\n"); return ERR_INVALID_INPUT; } if (lines_read ++ > MAX_LINES) { printf("Too many lines\n"); return ERR_TOO_MUCH_INPUT; } + + if (buf[len-2] != '\r') { + if (buf[len-1] != '\n') { + printf("Line too long.\n"); + return ERR_INVALID_INPUT; + } + buf[len-1] = '\r'; + buf[len] = '\n'; + buf[len+1] = '\0'; + len++; + } + if (strcmp("-----BEGIN CERTIFICATE LIST-----\r\n", buf) == 0){ readingList = 1; continue;