summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-04-07 01:14:25 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-04-07 01:14:25 +0200
commit4abebddcd6f01958c078080c5e6303fca68349cf (patch)
tree9350d49d653b3ecd9c4a692888150f3bfac558ab /lib
parente9b678665b6714501f0bd771b311ec300562465e (diff)
downloadgnutls-4abebddcd6f01958c078080c5e6303fca68349cf.tar.gz
simplified cdk_trim_string() to make it safer to use.
Diffstat (limited to 'lib')
-rw-r--r--lib/opencdk/literal.c8
-rw-r--r--lib/opencdk/main.h2
-rw-r--r--lib/opencdk/misc.c13
3 files changed, 12 insertions, 11 deletions
diff --git a/lib/opencdk/literal.c b/lib/opencdk/literal.c
index 4c8f966124..a36921c0d7 100644
--- a/lib/opencdk/literal.c
+++ b/lib/opencdk/literal.c
@@ -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);
}
diff --git a/lib/opencdk/main.h b/lib/opencdk/main.h
index a8803081f8..8b785f90a2 100644
--- a/lib/opencdk/main.h
+++ b/lib/opencdk/main.h
@@ -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);
diff --git a/lib/opencdk/misc.c b/lib/opencdk/misc.c
index 46632a4b03..d6a89aeb86 100644
--- a/lib/opencdk/misc.c
+++ b/lib/opencdk/misc.c
@@ -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';
}