Fix auto-pair-blacklist file size continuing to grow when bond fails 84/321284/1
authorWootak Jung <wootak.jung@samsung.com>
Tue, 18 Mar 2025 08:24:50 +0000 (17:24 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 18 Mar 2025 08:32:55 +0000 (17:32 +0900)
Change-Id: Ida1339cb7053055edcf03a736c00a0a51347a142
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-service/services/device/bt-service-core-device.c

index 68fe507eddce0f8ab3a966bb7449e76b987acb4a..6d260202fdca8f4df27c919901efd8581dc2f38f 100644 (file)
@@ -2659,10 +2659,11 @@ static gboolean __bt_ignore_auto_pairing_request(const char *address)
        char **lines;
        int i;
        char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
-       char *temp_buffer;
        FILE *fp;
        long size;
        size_t result;
+       int count = 0;
+       char *token;
 
        BT_DBG("+\n");
 
@@ -2700,20 +2701,29 @@ static gboolean __bt_ignore_auto_pairing_request(const char *address)
                return FALSE;
        }
 
-       lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
-       g_free(buffer);
-
-       if (lines == NULL)
+       for (char *p = buffer; (p = strstr(p, "\r\n")); p += 2)
+               count++;
+       lines = g_malloc0(sizeof(char *) * (count + 1));
+       if (lines == NULL) {
+               g_free(buffer);
                return FALSE;
+       }
 
-       /* Write the data and insert new device data */
-       for (i = 0; lines[i] != NULL; i++) {
-               if (g_str_has_prefix(lines[i], "AddressBlocklist")) {
-                       temp_buffer = g_strconcat(lines[i], lap_address, NULL);
+       token = strtok(buffer, "\r\n");
+       for (i = 0; i < count; i++) {
+               if (g_str_has_prefix(token, "AddressBlocklist"))
+                       lines[i] = g_strconcat(token, lap_address, NULL);
+               else
+                       lines[i] = g_strdup(token);
+
+               if (i == count - 1) {
                        g_free(lines[i]);
-                       lines[i] = temp_buffer;
+                       lines[i] = g_strconcat(token, "\r\n", NULL);
                }
+               token = strtok(NULL, "\r\n");
        }
+       g_free(buffer);
+
        buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
        g_strfreev(lines);
        /* Fix : NULL_RETURNS */