diff cinst/main.c @ 126:898446d9d23e

Normalize input if neccessary
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 24 Mar 2014 10:13:55 +0000
parents 24fb90ef8f6a
children 4904fe01055d
line wrap: on
line diff
--- 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;

http://wald.intevation.org/projects/trustbridge/