]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
simplified cdk_trim_string() to make it safer to use.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 6 Apr 2011 23:14:25 +0000 (01:14 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 6 Apr 2011 23:14:25 +0000 (01:14 +0200)
lib/opencdk/literal.c
lib/opencdk/main.h
lib/opencdk/misc.c

index 4c8f966124ad9a18eeed2feff5511ce8aa1f9ee0..a36921c0d7d1b4dd33483121ae1ff3cc42c87ae8 100644 (file)
@@ -262,10 +262,12 @@ text_encode (void *data, FILE * in, FILE * out)
   /* FIXME: This code does not work for very long lines. */
   while (!feof (in))
     {
-      s = fgets (buf, DIM (buf) - 1, in);
+      /* give space for trim_string \r\n */
+      s = fgets (buf, DIM (buf) - 3, in);
       if (!s)
         break;
-      _cdk_trim_string (buf, 1);
+      _cdk_trim_string (buf);
+      strcat (buf, "\r\n");
       fwrite (buf, 1, strlen (buf), out);
     }
 
@@ -288,7 +290,7 @@ text_decode (void *data, FILE * in, FILE * out)
       s = fgets (buf, DIM (buf) - 1, in);
       if (!s)
         break;
-      _cdk_trim_string (buf, 0);
+      _cdk_trim_string (buf);
       fwrite (buf, 1, strlen (buf), out);
       fwrite (tfx->lf, 1, strlen (tfx->lf), out);
     }
index a8803081f884c7fbabf174f272868e572f42cbca..8b785f90a28e6f2115a8b624fe1175b540182e41 100644 (file)
@@ -158,7 +158,7 @@ cdk_error_t _cdk_keydb_check_userid (cdk_keydb_hd_t hd, u32 * keyid,
 
 /*-- sign.c --*/
 int _cdk_sig_hash_for (cdk_pkt_pubkey_t pk);
-void _cdk_trim_string (char *s, int canon);
+void _cdk_trim_string (char *s);
 cdk_error_t _cdk_sig_create (cdk_pkt_pubkey_t pk, cdk_pkt_signature_t sig);
 cdk_error_t _cdk_sig_complete (cdk_pkt_signature_t sig, cdk_pkt_seckey_t sk,
                                digest_hd_st * hd);
index 46632a4b038ac6bf7fc570fb22c40dbe5a990b4e..d6a89aeb86b6794d21db7aa698c7a58e16c32167 100644 (file)
@@ -146,15 +146,14 @@ _cdk_map_gnutls_error (int err)
 
 /* Remove all trailing white spaces from the string. */
 void
-_cdk_trim_string (char *s, int canon)
+_cdk_trim_string (char *s)
 {
+int len = strlen(s);
   while (s && *s &&
-         (s[strlen (s) - 1] == '\t' ||
-          s[strlen (s) - 1] == '\r' ||
-          s[strlen (s) - 1] == '\n' || s[strlen (s) - 1] == ' '))
-    s[strlen (s) - 1] = '\0';
-  if (canon)
-    strcat (s, "\r\n");
+         (s[len - 1] == '\t' ||
+          s[len - 1] == '\r' ||
+          s[len - 1] == '\n' || s[len - 1] == ' '))
+    s[len - 1] = '\0';
 }