summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-04 15:53:05 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-06 12:57:07 +0200
commita2cf89a42aff91e009ca024d24bee33970c37103 (patch)
tree3b4bc774bfefd5678bc776ec31694e4ebfda6d76
parent28e723ca0b830abe3b36f401b001d74359a6c200 (diff)
downloadgnutls-a2cf89a42aff91e009ca024d24bee33970c37103.tar.gz
_gnutls_x509_write_uint32: ensure we prepend leading zero when writing
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/x509/mpi.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/x509/mpi.c b/lib/x509/mpi.c
index 2e7cdc2802..2bb3e54aaa 100644
--- a/lib/x509/mpi.c
+++ b/lib/x509/mpi.c
@@ -28,6 +28,7 @@
#include "common.h"
#include "x509_int.h"
#include <num.h>
+#include <limits.h>
/* Reads an Integer from the DER encoded data
*/
@@ -319,12 +320,17 @@ _gnutls_x509_read_uint(ASN1_TYPE node, const char *value,
int
_gnutls_x509_write_uint32(ASN1_TYPE node, const char *value, uint32_t num)
{
- uint8_t tmpstr[4];
+ uint8_t tmpstr[5];
int result;
- _gnutls_write_uint32(num, tmpstr);
+ tmpstr[0] = 0;
+ _gnutls_write_uint32(num, tmpstr+1);
- result = asn1_write_value(node, value, tmpstr, 4);
+ if (tmpstr[1] > SCHAR_MAX) {
+ result = asn1_write_value(node, value, tmpstr, 5);
+ } else {
+ result = asn1_write_value(node, value, tmpstr+1, 4);
+ }
if (result != ASN1_SUCCESS) {
gnutls_assert();