]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
edit: Limit maximum number of history entries to 100
authorJouni Malinen <j@w1.fi>
Sun, 21 Nov 2010 10:04:44 +0000 (12:04 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 21 Nov 2010 10:04:44 +0000 (12:04 +0200)
src/utils/edit.c

index 836397d4351c67e0bc5ebd6f31474d24b05e56d0..ad909272a7d2b47402d4c2d8b55bec4cd3054373 100644 (file)
@@ -25,6 +25,8 @@ static char cmdbuf[CMD_BUF_LEN];
 static int cmdbuf_pos = 0;
 static int cmdbuf_len = 0;
 
+#define HISTORY_MAX 100
+
 struct edit_history {
        struct dl_list list;
        char str[1];
@@ -176,8 +178,8 @@ static void clear_right(void)
 
 static void history_add(const char *str)
 {
-       struct edit_history *h, *match = NULL;
-       size_t len;
+       struct edit_history *h, *match = NULL, *last = NULL;
+       size_t len, count = 0;
 
        if (str[0] == '\0')
                return;
@@ -187,6 +189,8 @@ static void history_add(const char *str)
                        match = h;
                        break;
                }
+               last = h;
+               count++;
        }
 
        if (match) {
@@ -196,6 +200,11 @@ static void history_add(const char *str)
                return;
        }
 
+       if (count >= HISTORY_MAX && last) {
+               dl_list_del(&last->list);
+               os_free(last);
+       }
+
        len = os_strlen(str);
        h = os_zalloc(sizeof(*h) + len);
        if (h == NULL)