Revision: 19748
          http://sourceforge.net/p/edk2/code/19748
Author:   qlong
Date:     2016-01-26 08:51:13 +0000 (Tue, 26 Jan 2016)
Log Message:
-----------
CryptoPkg: Fix function qsort for non 32-bit machines

Although the function qsort receives as an argument a "compare" function
which returns an "int", QuickSortWorker (the function used internally by
qsort to do its job) receives as an argument a "CompareFunction" which
returns an "INTN". In a 32-bit machine, "INTN" is defined as "INT32",
which is defined as "int" and everything works well. However, when qsort
is compiled for a 64-bit machine, "INTN" is defined as "INT64" and the
return values of the compare functions become incompatible ("int" for
qsort and "INT64" for QuickSortWorker), causing malfunction.

For example, let's assume qsort is being compiled for a 64-bit machine.
As stated before, the "compare" function will be returning an "int",
and "CompareFunction" will be returning an "INT64". When, for example,
the "compare" function (which was passed as an argument to qsort and,
then, re-passed as an argument to QuickSortWorker) returns -1 (or
0xffffffff, in a 32-bit integer, its original return type) from inside
a call to QuickSortWorker, its return value is interpreted as being an
"INT64" value - which turns out to be 4294967295 (or 0x00000000ffffffff,
in a 64-bit integer) -, making the function QuickSortWorker to behave
unexpectedly.

Note that this unexpected (or incorrect) conversion does not happen when
casting an "INT32" to an "INT64" directly, but does happen when casting
function types.

The issue is fixed by changing the return type of SORT_COMPARE (the type
of "CompareFunction", used by QuickSortWorker) from "INTN" to "int".
This way, both qsort and QuickSortWorker use compatible definitions for
their compare functions.

Contributed-under: TianoCore Contribution Agreement 1.0
Acked-by: Paulo Alcantara Cavalcanti <[email protected]>
Signed-off-by: Karyne Mayer <[email protected]>
Signed-off-by: Rodrigo Dias Correa <[email protected]>
Signed-off-by: Arthur Crippa Burigo <[email protected]>
Reviewed-by: Qin Long <[email protected]>

Modified Paths:
--------------
    trunk/edk2/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c

Modified: trunk/edk2/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
===================================================================
--- trunk/edk2/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c      
2016-01-26 08:45:34 UTC (rev 19747)
+++ trunk/edk2/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c      
2016-01-26 08:51:13 UTC (rev 19748)
@@ -2,7 +2,7 @@
   C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based
   Cryptographic Library.
 
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -22,7 +22,7 @@
 FILE  *stdout = NULL;
 
 typedef
-INTN
+int
 (*SORT_COMPARE)(
   IN  VOID  *Buffer1,
   IN  VOID  *Buffer2


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to