Skip to content

Commit

Permalink
Fix uncaught error if fix_negative fails
Browse files Browse the repository at this point in the history
fix_negative allocates memory for its result. The calling site didn't
check the return value, so an out-of-memory error could lead to an
incorrect calculation. Fix this.

Signed-off-by: Gilles Peskine <[email protected]>
  • Loading branch information
gilles-peskine-arm committed Jul 22, 2020
1 parent 84697ca commit 7d6326d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/ecp_curves.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
STORE32; i++; \
cur = c > 0 ? c : 0; STORE32; \
cur = 0; while( ++i < MAX32 ) { STORE32; } \
if( c < 0 ) fix_negative( N, c, &C, bits );
if( c < 0 ) MBEDTLS_MPI_CHK( fix_negative( N, c, &C, bits ) );

/*
* If the result is negative, we get it in the form
Expand Down

0 comments on commit 7d6326d

Please sign in to comment.