]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
fix build error
authorlongpanda <admin@ventoy.net>
Fri, 17 Jun 2022 04:25:21 +0000 (12:25 +0800)
committerlongpanda <admin@ventoy.net>
Fri, 17 Jun 2022 04:25:21 +0000 (12:25 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c

index d7bd0064193f502828495db8f130a97cd33b2c81..a5d692f24e3587f2a87eedcb905e8d10092e42df 100644 (file)
@@ -3367,30 +3367,76 @@ end:
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
+static int ventoy_is_builtin_var(const char *var)
+{
+    int i;
+    const char *c;
+    const char *builtin_vars_full[] = 
+    {
+        "VT_DISK_1ST_NONVTOY",
+        "VT_DISK_1ST_NONUSB",
+        NULL
+    };
+
+    for (i = 0; builtin_vars_full[i]; i++)
+    {
+        if (grub_strcmp(builtin_vars_full[i], var) == 0)
+        {
+            return 1;
+        }
+    }
+
+    if (grub_strncmp(var, "VT_DISK_CLOSEST_", 16) == 0)
+    {
+        c = var + 16;
+        while (*c)
+        {
+            if (*c < '0' || *c > '9')
+            {
+                break;
+            }
+            c++;
+        }
+
+        if (*c == 0 && c != (var + 16))
+        {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
 static int ventoy_var_expand(int *flag, const char *var, char *expand, int len)
 {
     int i = 0;
     int n = 0;
     char c;
 static int ventoy_var_expand(int *flag, const char *var, char *expand, int len)
 {
     int i = 0;
     int n = 0;
     char c;
-    const char *c = var;
-    grub_uint8_t bytes[32];
+    const char *ch = var;
 
     expand[0] = 0;
 
 
     expand[0] = 0;
 
-    while (*c)
+    while (*ch)
     {
     {
-        if (*c == '_' || (*c >= '0' && *c <= '9') || (*c >= 'A' && *c <= 'Z'))
+        if (*ch == '_' || (*ch >= '0' && *ch <= '9') || (*ch >= 'A' && *ch <= 'Z'))
         {
         {
-            c++;            
+            ch++;
+            n++;
         }
         else
         {
         }
         else
         {
-            debug("Invalid variable letter <%c>\n", *c);
+            debug("Invalid variable letter <%c>\n", *ch);
             goto end;
         }
     }
 
             goto end;
         }
     }
 
-    if (grub_strncmp(var, "VT_RAND_9", 9) == 0)
+    if (n > 32)
+    {
+        debug("Invalid variable length:%d <%s>\n", n, var);
+        goto end;
+    }
+
+    if (ventoy_is_builtin_var(var))
     {
         
     }
     {
         
     }
@@ -3447,7 +3493,7 @@ static int ventoy_var_expand(int *flag, const char *var, char *expand, int len)
 end:
     if (expand[0] == 0)
     {
 end:
     if (expand[0] == 0)
     {
-        grub_snprintf(expand, len, "$<%s>$", var);
+        grub_snprintf(expand, len, "$$%s$$", var);
     }
     
     return 0;
     }
     
     return 0;
@@ -3480,14 +3526,14 @@ static int ventoy_auto_install_var_expand(install_template *node)
         return 0;
     }
 
         return 0;
     }
 
-    start = grub_strstr(node->filebuf, "$<");
+    start = grub_strstr(node->filebuf, "$$");
     if (!start)
     {
         debug("no need to expand variable, no start.\n");
         return 0;
     }
 
     if (!start)
     {
         debug("no need to expand variable, no start.\n");
         return 0;
     }
 
-    end = grub_strstr(start + 2, ">$");
+    end = grub_strstr(start + 2, "$$");
     if (!end)
     {
         debug("no need to expand variable, no end.\n");
     if (!end)
     {
         debug("no need to expand variable, no end.\n");
@@ -3506,10 +3552,10 @@ static int ventoy_auto_install_var_expand(install_template *node)
     {
         nextline = ventoy_get_line(curline);
 
     {
         nextline = ventoy_get_line(curline);
 
-        start = grub_strstr(curline, "$<");
+        start = grub_strstr(curline, "$$");
         if (start)
         {
         if (start)
         {
-            end = grub_strstr(start + 2, ">$");
+            end = grub_strstr(start + 2, "$$");
         }
 
         if (start && end)
         }
 
         if (start && end)