Path bounds checks
authorLukas Krickl <lukas@krickl.dev>
Sat, 9 Dec 2023 17:27:50 +0000 (18:27 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 9 Dec 2023 17:27:50 +0000 (18:27 +0100)
src/ulas.c

index a6b27580f10eb853b948981d9aa6aa443736b48a..cf03bc3803c155b36ef295da6ea8b9c0b5634b89 100644 (file)
@@ -65,11 +65,15 @@ void ulas_free(void) {
 FILE *ulas_incpathfopen(const char *path, const char *mode) {
   char pathbuf[ULAS_PATHMAX];
   memset(pathbuf, 0, ULAS_PATHMAX);
+  int baselen = strlen(path);
   
   for (int i = 0; i < ulas.include_paths_len; i++) {
     pathbuf[0] = '\0';
     char *ip = ulas.include_paths[i];
     int len = strlen(ip);
+    if (len + baselen + 1 >= ULAS_PATHMAX) {
+      continue;
+    }
 
     strcat(pathbuf, ip);
     if (ip[len-1] != ULAS_PATHSEP[0]) {