From: Nikos Mavrogiannopoulos Date: Wed, 6 Apr 2011 23:14:25 +0000 (+0200) Subject: simplified cdk_trim_string() to make it safer to use. X-Git-Tag: gnutls_2_99_0~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4abebddcd6f01958c078080c5e6303fca68349cf;p=thirdparty%2Fgnutls.git simplified cdk_trim_string() to make it safer to use. --- 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'; }