* grub-core/commands/menuentry.c (setparams_prefix): Use single
quotes for arguments.
+ * grub-core/lib/legacy_parse.c (grub_legacy_escape): Use
+ grub_script_escape_squotes function instead.
+
+ * include/grub/script_sh.h (grub_script_escape_squotes): New
+ prototype.
+ * grub-core/script/script.c (grub_script_escape_squotes): New
+ function.
2010-11-18 Vladimir Serbinenko <phcoder@gmail.com>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/normal.h>
+#include <grub/script_sh.h>
static const struct grub_arg_option options[] =
{
return 0;
grub_strcpy (result, "setparams");
- i = 9;
+ p = result + 9;
for (j = 0; j < argc; j++)
{
- result[i++] = ' ';
- result[i++] = '\'';
- p = args[j];
- while (*p) {
- result[i++] = *p;
- if (*p == '\'') {
- result[i++] = '\\';
- result[i++] = '\'';
- result[i++] = '\'';
- }
- p++;
- }
- result[i++] = '\'';
+ *p++ = ' ';
+ *p++ = '\'';
+ p = grub_script_escape_squotes (p, args[j], grub_strlen (args[j]));
+ *p++ = '\'';
}
- result[i++] = '\n';
- result[i] = '\0';
+ *p++ = '\n';
+ *p = '\0';
return result;
}
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
+#include <grub/script_sh.h>
#include <grub/legacy_parse.h>
#include <grub/i386/pc/vesa_modes_table.h>
grub_legacy_escape (const char *in, grub_size_t len)
{
const char *ptr;
- char *ret, *outptr;
+ char *outptr;
int overhead = 0;
for (ptr = in; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'')
overhead += 3;
- ret = grub_malloc (ptr - in + overhead + 1);
- if (!ret)
+ outptr = grub_malloc (ptr - in + overhead + 1);
+ if (!outptr)
return NULL;
- outptr = ret;
- for (ptr = in; ptr < in + len && *ptr; ptr++)
- {
- if (*ptr == '\'')
- {
- *outptr++ = '\'';
- *outptr++ = '\\';
- *outptr++ = '\'';
- *outptr++ = '\'';
- continue;
- }
-
- *outptr++ = *ptr;
- }
- *outptr++ = 0;
- return ret;
+ grub_script_escape_squotes (outptr, in, len);
+ return outptr;
}
static char *
#include <grub/parser.h>
#include <grub/mm.h>
+/* Escape single quotes in first `len' characters of `in' into a GRUB
+ script argument form into `out'; return address of the end in
+ `out'. */
+char *
+grub_script_escape_squotes (char *out, const char *in, grub_size_t len)
+{
+ while (*in && len--)
+ {
+ *out++ = *in;
+ if (*in == '\'')
+ {
+ *out++ = '\\';
+ *out++ = '\'';
+ *out++ = '\'';
+ }
+ in++;
+ }
+ *out = '\0';
+ return out;
+}
+
/* It is not possible to deallocate the memory when a syntax error was
found. Because of that it is required to keep track of all memory
allocations. The memory is freed in case of an error, or assigned
grub_err_t
grub_normal_parse_line (char *line, grub_reader_getline_t getline);
+char *
+grub_script_escape_squotes (char *out, const char *in, grub_size_t len);
+
static inline struct grub_script *
grub_script_ref (struct grub_script *script)
{