Fix bad null check in pal_dsa.c
authorOmair Majid <omajid@redhat.com>
Mon, 8 Apr 2019 14:40:49 +0000 (10:40 -0400)
committerJeremy Barton <jbarton@microsoft.com>
Sun, 14 Apr 2019 00:29:35 +0000 (17:29 -0700)
commit92e4fece70da72f069ffe7d8ba462d5ada90031b
treeb1da5804cedeb59063826762fe021ae7887b3c9d
parentd5e7e4004e3b3fd8af7bf6e74df5ecc073cbf5c1
Fix bad null check in pal_dsa.c

The code calls DSA_new() and then, only after assigning the value from
DSA_new to a pointer, tries to check that the pointer was not null.
Assigning to a null pointer leads to undefined behaviour and a compiler
can assume that assignment-to-a-null-pointer wont happen. Subsequently,
the compiler can remove the entire check because the pointer can't be
null.

Fix that by:

1. Moving the check for whether the pointer is null before dereferncing
   the pointer.

2. Checking the return value of DSA_new() spearately after it has been
   called.

Commit migrated from https://github.com/dotnet/corefx/commit/e7fd1669eafafd16de85cd90b558d54abb3a3343
src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_dsa.c