From 05feca6f7cc26a22950d17f74c63a7b5e7a20eed Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Sat, 20 Jun 2009 08:22:43 +0000
Subject: [PATCH] - Fixed incorrect handling of negative strings in
mpi_read_string() (found by code coverage tests).
---
ChangeLog | 5 +++++
library/bignum.c | 10 +++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 9a1a52d86..e84a35525 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
PolarSSL ChangeLog
+= Version X released on X
+Bug fixes
+ * Fixed incorrect handling of negative strings in
+ mpi_read_string() (found by code coverage tests).
+
= Version 0.11.1 released on 2009-05-17
* Fixed missing functionality for SHA-224, SHA-256, SHA384,
SHA-512 in rsa_pkcs1_sign()
diff --git a/library/bignum.c b/library/bignum.c
index 4b8fa8030..5c1de684c 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -286,7 +286,15 @@ int mpi_read_string( mpi *X, int radix, char *s )
MPI_CHK( mpi_get_digit( &d, radix, s[i] ) );
MPI_CHK( mpi_mul_int( &T, X, radix ) );
- MPI_CHK( mpi_add_int( X, &T, d ) );
+
+ if( X->s == 1 )
+ {
+ MPI_CHK( mpi_add_int( X, &T, d ) );
+ }
+ else
+ {
+ MPI_CHK( mpi_sub_int( X, &T, d ) );
+ }
}
}