]> git.sur5r.net Git - i3/i3/blobdiff - src/cfgparse.y
Bugfix: use bufcopy instead of buf when boundary checking (Thanks thomasba)
[i3/i3] / src / cfgparse.y
index a80e25afac808de6e073e97cc1c7b8ccb0d0ebd8..dc29860cda021f1f23552ed0bfce8cfaf25aa2d6 100644 (file)
@@ -188,6 +188,7 @@ static char *migrate_config(char *input, off_t size) {
         ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
         if (ret == -1) {
             warn("Cannot read from pipe");
+            FREE(converted);
             return NULL;
         }
         read_bytes += ret;
@@ -357,12 +358,14 @@ void parse_file(const char *f) {
 
             /* get key/value for this variable */
             char *v_key = value, *v_value;
-            if ((v_value = strstr(value, " ")) == NULL &&
-                (v_value = strstr(value, "\t")) == NULL) {
+            if (strstr(value, " ") == NULL && strstr(value, "\t") == NULL) {
                 ELOG("Malformed variable assignment, need a value\n");
                 continue;
             }
 
+            if (!(v_value = strstr(value, " ")))
+                v_value = strstr(value, "\t");
+
             *(v_value++) = '\0';
 
             struct Variable *new = scalloc(sizeof(struct Variable));
@@ -387,7 +390,8 @@ void parse_file(const char *f) {
         int extra = (strlen(current->value) - strlen(current->key));
         char *next;
         for (next = bufcopy;
-             (next = strcasestr(bufcopy + (next - bufcopy), current->key)) != NULL;
+             next < (bufcopy + stbuf.st_size) &&
+             (next = strcasestr(next, current->key)) != NULL;
              next += strlen(current->key)) {
             *next = '_';
             extra_bytes += extra;
@@ -658,6 +662,10 @@ bindsym:
 for_window:
     TOK_FOR_WINDOW match command
     {
+        if (match_is_empty(&current_match)) {
+            ELOG("Match is empty, ignoring this for_window statement\n");
+            break;
+        }
         printf("\t should execute command %s for the criteria mentioned above\n", $3);
         Assignment *assignment = scalloc(sizeof(Assignment));
         assignment->type = A_COMMAND;
@@ -941,10 +949,25 @@ workspace:
             }
 
             DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
-            struct Workspace_Assignment *assignment = scalloc(sizeof(struct Workspace_Assignment));
-            assignment->name = ws_name;
-            assignment->output = $4;
-            TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
+            /* Check for earlier assignments of the same workspace so that we
+             * don’t have assignments of a single workspace to different
+             * outputs */
+            struct Workspace_Assignment *assignment;
+            bool duplicate = false;
+            TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
+                if (strcasecmp(assignment->name, ws_name) == 0) {
+                    ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
+                         ws_name);
+                    assignment->output = $4;
+                    duplicate = true;
+                }
+            }
+            if (!duplicate) {
+                assignment = scalloc(sizeof(struct Workspace_Assignment));
+                assignment->name = ws_name;
+                assignment->output = $4;
+                TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
+            }
         }
     }
     | TOKWORKSPACE NUMBER workspace_name