Fix the prevent problems
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Sat, 26 Jan 2013 05:01:03 +0000 (14:01 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Sat, 26 Jan 2013 05:13:10 +0000 (14:13 +0900)
 - Check return value

Change-Id: Idcc6e69472630df08310894c3a2b5006adf9b525

common/OpensslHelper.cpp
packaging/smartcard-service.spec

index 6cbef8a..52161d7 100644 (file)
@@ -1,18 +1,18 @@
 /*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 /* standard library header */
 #include <stdio.h>
@@ -125,7 +125,6 @@ namespace smartcard_service_api
        bool OpensslHelper::digestBuffer(const char *algorithm, const ByteArray &buffer, ByteArray &result)
        {
                const EVP_MD *md;
-               unsigned char *temp;
                bool ret = false;
 
                if (algorithm == NULL || buffer.getLength() == 0)
@@ -137,30 +136,23 @@ namespace smartcard_service_api
 
                if ((md = EVP_get_digestbyname(algorithm)) != NULL)
                {
-                       temp = new unsigned char[EVP_MAX_MD_SIZE];
-                       if (temp != NULL)
-                       {
-                               EVP_MD_CTX mdCtx;
-                               unsigned int resultLen = 0;
-
-                               memset(temp, 0, EVP_MAX_MD_SIZE);
+                       uint8_t temp[EVP_MAX_MD_SIZE] = { 0, };
+                       EVP_MD_CTX mdCtx;
+                       unsigned int resultLen = 0;
 
-                               EVP_DigestInit(&mdCtx, md);
-                               if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.getLength()) != 0)
+                       if (EVP_DigestInit(&mdCtx, md) > 0)
+                       {
+                               if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.getLength()) == 0)
                                {
                                        SCARD_DEBUG_ERR("EVP_DigestUpdate failed");
                                }
-                               EVP_DigestFinal(&mdCtx, temp, &resultLen);
-
-                               result.setBuffer(temp, resultLen);
-
-                               delete []temp;
 
-                               ret = true;
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("alloc failed");
+                               if (EVP_DigestFinal(&mdCtx, temp, &resultLen) > 0 &&
+                                       resultLen > 0)
+                               {
+                                       result.setBuffer(temp, resultLen);
+                                       ret = true;
+                               }
                        }
                }
                else
index edaf4b2..66032cf 100644 (file)
@@ -1,7 +1,7 @@
 Name:       smartcard-service
 Summary:    Smartcard Service FW
-Version:    0.1.9
-Release:    1
+Version:    0.1.11
+Release:    0
 Group:      libs
 License:    Apache License, Version 2.0
 Source0:    %{name}-%{version}.tar.gz