Modify ppm_popup_send_response to handle 0-length response 97/226897/7
authorTomasz Swierczek <t.swierczek@samsung.com>
Fri, 6 Mar 2020 06:49:28 +0000 (07:49 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Mon, 9 Mar 2020 06:27:00 +0000 (07:27 +0100)
Response sent with 0 as length of data will be treated
as DENY_ONCE for all privacies in original request.

Change-Id: I1e356ba1151507cb4cde5b61744c29c8ce0818e0

src/capi/impl/privacy_privilege_manager.c
src/capi/include/ppm_popup.h
src/client/api/askuser-notification-client.cpp
src/client/include/askuser-notification-client.h
src/ipc/message-utils.h
src/ipc/server-channel.cpp

index 49efb1f..b659f54 100644 (file)
@@ -502,7 +502,7 @@ int ppm_popup_send_response(int popup_id,
                             ppm_popup_response_e *responses,
                             size_t privacies_count)
 {
-    if (!privacies || !responses || privacies_count < 1) {
+    if (((!privacies || !responses) && privacies_count > 0) || (privacies_count == 0 && (privacies || responses))) {
         return PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER;
     }
 
@@ -511,25 +511,29 @@ int ppm_popup_send_response(int popup_id,
         return ret;
     }
 
-    askuser_popup_result* aresults = (askuser_popup_result*) calloc(1, sizeof(askuser_popup_result) * privacies_count);
-    if (!aresults) {
-        return PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY;
-    }
+    askuser_popup_result* aresults = NULL;
+
+    if (privacies_count > 0) {
+        aresults = (askuser_popup_result*) calloc(1, sizeof(askuser_popup_result) * privacies_count);
+        if (!aresults) {
+            return PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY;
+        }
 
-    for (size_t i = 0; i < privacies_count; ++i) {
-        switch( responses[i] ) {
-            case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_ALLOW_FOREVER :
-                aresults[i] = ASKUSER_POPUP_RESULT_ALLOW_FOREVER;
-                break;
-            case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_FOREVER :
-                aresults[i] = ASKUSER_POPUP_RESULT_DENY_FOREVER;
-                break;
-            case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_ONCE :
-                aresults[i] = ASKUSER_POPUP_RESULT_DENY_ONCE;
-                break;
-            default:
-                free(aresults);
-                return PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER;
+        for (size_t i = 0; i < privacies_count; ++i) {
+            switch( responses[i] ) {
+                case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_ALLOW_FOREVER :
+                    aresults[i] = ASKUSER_POPUP_RESULT_ALLOW_FOREVER;
+                    break;
+                case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_FOREVER :
+                    aresults[i] = ASKUSER_POPUP_RESULT_DENY_FOREVER;
+                    break;
+                case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_ONCE :
+                    aresults[i] = ASKUSER_POPUP_RESULT_DENY_ONCE;
+                    break;
+                default:
+                    free(aresults);
+                    return PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER;
+            }
         }
     }
 
index 0d0e8f9..33fa5a5 100644 (file)
@@ -53,6 +53,8 @@ typedef enum {
  * @param[in]   privacies         The privacies array for which user response has been acquired.
  * @param[in]   responses         The responses array for corresponding privacies.
  * @param[in]   privacies_count   The number of elements in the privacies and results arrays.
+ *                                If set to 0, both privacies and responses need to be set to NULL
+ *                                and API will operate as if DENY_ONCE answer was passed to askuser.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE               Successful
index b378371..a65c081 100644 (file)
@@ -243,7 +243,7 @@ int askuser_popup_send_ext_response(askuser_client *p_client, int popup_id,
                             const askuser_popup_result responses[],
                             size_t privacies_count)
 {
-    if (!privacies || !responses || privacies_count < 1) {
+    if (((!privacies || !responses) && privacies_count > 0) || (privacies_count == 0 && (privacies || responses))) {
         return ASKUSER_API_INVALID_PARAM;
     }
 
index 3533079..2a75a40 100644 (file)
@@ -702,6 +702,8 @@ int askuser_client_popup_multiple_request(askuser_client *p_client, const char *
  * \param[in]   privacies         The privacies array for which user response has been acquired.
  * \param[in]   responses         The responses array for corresponding privacies.
  * \param[in]   privacies_count   The number of elements in the privacies and results arrays.
+ *                                If set to 0, both privacies and responses need to be set to NULL
+ *                                and API will operate as if DENY_ONCE answer was passed to askuser.
  *
  * \return ASKUSER_API_SUCCESS on success
  * \return a negative value in case of an error (see "Status return codes")
index 8113613..59646db 100644 (file)
@@ -83,12 +83,7 @@ const std::size_t MIN_EXT_RESPONSE_MESSAGE_LENGHT = MIN_COMMAND_LENGTH +
                                                SEP_LEN + // space
                                                MIN_EXT_RESPONSE_POPUP_ID_LEN +
                                                SEP_LEN + // space
-                                               MIN_PRIVS_NUMBER_LENGTH +
-                                               MIN_PRIVS_NUMBER * (
-                                               SEP_LEN + // space
-                                               MIN_PRIVILEGE_ENC_LENGTH + // assuming privacy can't be longer than privilege
-                                               SEP_LEN + // space
-                                               MIN_RESPONSE_STATUS_LEN) + // response
+                                               MIN_PRIVS_NUMBER_LENGTH + // in case vectors have lenght 0
                                                SEP_LEN; // new line
 
 const std::size_t MAX_EXT_RESPONSE_MESSAGE_LENGHT = MAX_COMMAND_LENGTH +
@@ -165,7 +160,7 @@ const unsigned int ASKUSER_MESSAGE_REQUESTID_POS = 1;
 const unsigned int ASKUSER_MESSAGE_PRIVILEGES_COUNT_POS = 2;
 const unsigned int ASKUSER_MESSAGE_FIRST_PRIVILEGE_POS = 3;
 const unsigned int ASKUSER_MESSAGE_MIN_MSG_PARAM_COUNT = 4; //cmd, requestId, privilegeCount, privilege
-const unsigned int ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT = 5; //cmd, popup_id, privacyCount, privacy, response
+const unsigned int ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT = 3; //cmd, popup_id, privacyCount == 0
 const unsigned int ASKUSER_MESSAGE_SEND_SYNC_MSG_RESULT_PARAM_COUNT = 2; //cmd, result
 const unsigned int ASKUSER_MESSAGE_EXT_RESPONSE_POPUP_ID_POS = 1;
 const unsigned int ASKUSER_MESSAGE_EXT_RESPONSE_PRIV_COUNT_POS = 2;
index 4d34312..4cec626 100644 (file)
@@ -163,7 +163,7 @@ int ServerChannel::onReceive(int fd, std::vector<std::string> &&message) {
             }
             popup_id = std::stoi(message[ASKUSER_MESSAGE_EXT_RESPONSE_POPUP_ID_POS]);
             privaciesCount = std::stoul(message[ASKUSER_MESSAGE_EXT_RESPONSE_PRIV_COUNT_POS]);
-            if (message.size() != 2 * privaciesCount + ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT - 2) {
+            if (message.size() != 2 * privaciesCount + ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT) {
                 ALOGE("Inappropriate message size for MSGID_EXT_POPUP_RESPONSE command, size: " << message.size());
                 return -EINVAL;
             }