From: Nikos Mavrogiannopoulos Date: Sun, 10 Apr 2011 07:22:43 +0000 (+0200) Subject: Changes armor.c to be able to handle both LF and CRLF inputs (output is X-Git-Tag: gnutls_2_99_1~72 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c7db40ee30adf7135a7c8953397b3a7cbded4177;p=thirdparty%2Fgnutls.git Changes armor.c to be able to handle both LF and CRLF inputs (output is still either LF-only or CRLF-only depending on the platform). Patch by LRN. Optimizations in the usage of strlen(). --- diff --git a/lib/opencdk/armor.c b/lib/opencdk/armor.c index 2928182d92..8491aa993c 100644 --- a/lib/opencdk/armor.c +++ b/lib/opencdk/armor.c @@ -40,8 +40,10 @@ #ifdef __MINGW32__ #define LF "\r\n" +#define ALTLF "\n" #else #define LF "\n" +#define ALTLF "\r\n" #endif #define CRCINIT 0xB704CE @@ -493,6 +495,7 @@ armor_decode (void *data, FILE * in, FILE * out) ssize_t nread = 0; int i, pgp_data = 0; cdk_error_t rc = 0; + int len; if (!afx) { @@ -526,7 +529,7 @@ armor_decode (void *data, FILE * in, FILE * out) s = fgets (buf, DIM (buf) - 1, in); if (!s) return CDK_EOF; - if (strlen (s) == strlen (LF)) + if (strcmp (s, LF) == 0 || strcmp (s, ALTLF) == 0) { rc = 0; break; /* empty line */ @@ -560,7 +563,13 @@ armor_decode (void *data, FILE * in, FILE * out) s = fgets (buf, DIM (buf) - 1, in); if (!s) break; - buf[strlen (buf) - strlen (LF)] = '\0'; + + len = strlen(buf); + + if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; + if (buf[len - 1] == '\r') + buf[len - 1] = '\0'; if (buf[0] == '=' && strlen (s) == 5) { /* CRC */ memset (crcbuf, 0, sizeof (crcbuf)); @@ -582,7 +591,11 @@ armor_decode (void *data, FILE * in, FILE * out) s = fgets (buf, DIM (buf) - 1, in); if (s) { - buf[strlen (buf) - strlen (LF)] = '\0'; + int len = strlen(buf); + if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; + if (buf[len - 1] == '\r') + buf[len - 1] = '\0'; rc = CDK_General_Error; afx->idx2 = search_header (buf, armor_end); if (afx->idx2 >= 0)