diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c index 4c63a14..f431343 100644 --- a/mpi/mpicoder.c +++ b/mpi/mpicoder.c @@ -680,16 +680,16 @@ _gcry_mpi_print (enum gcry_mpi_format format, extra = 1; } - if (buffer && n > len) - { - /* The provided buffer is too short. */ - xfree (tmp); - return GPG_ERR_TOO_SHORT; - } if (buffer) { unsigned char *s = buffer; + if (n > len) + { + /* The provided buffer is too short. */ + xfree (tmp); + return GPG_ERR_TOO_SHORT; + } if (extra == 1) *s++ = 0; else if (extra) @@ -707,13 +707,12 @@ _gcry_mpi_print (enum gcry_mpi_format format, /* Note: We ignore the sign for this format. */ /* FIXME: for performance reasons we should put this into mpi_aprint because we can then use the buffer directly. */ - - if (buffer && n > len) - return GPG_ERR_TOO_SHORT; if (buffer) { unsigned char *tmp; + if (n > len) + return GPG_ERR_TOO_SHORT; tmp = _gcry_mpi_get_buffer (a, 0, &n, NULL); if (!tmp) return gpg_err_code_from_syserror (); @@ -731,14 +730,14 @@ _gcry_mpi_print (enum gcry_mpi_format format, if (negative) return GPG_ERR_INV_ARG; - if (buffer && n+2 > len) - return GPG_ERR_TOO_SHORT; - if (buffer) { unsigned char *tmp; unsigned char *s = buffer; + if (n+2 > len) + return GPG_ERR_TOO_SHORT; + s[0] = nbits >> 8; s[1] = nbits; @@ -777,16 +776,16 @@ _gcry_mpi_print (enum gcry_mpi_format format, extra=1; } - if (buffer && n+4 > len) - { - xfree(tmp); - return GPG_ERR_TOO_SHORT; - } - if (buffer) { unsigned char *s = buffer; + if (n+4 > len) + { + xfree(tmp); + return GPG_ERR_TOO_SHORT; + } + *s++ = n >> 24; *s++ = n >> 16; *s++ = n >> 8; @@ -814,15 +813,15 @@ _gcry_mpi_print (enum gcry_mpi_format format, if (!n || (*tmp & 0x80)) extra = 2; - if (buffer && 2*n + extra + negative + 1 > len) - { - xfree(tmp); - return GPG_ERR_TOO_SHORT; - } if (buffer) { unsigned char *s = buffer; + if (2*n + extra + negative + 1 > len) + { + xfree(tmp); + return GPG_ERR_TOO_SHORT; + } if (negative) *s++ = '-'; if (extra)