replaced with grub_strchrsub function
This commit is contained in:
parent
d7647bb670
commit
5b08062083
5 changed files with 31 additions and 28 deletions
|
@ -228,7 +228,7 @@ setparams_prefix (int argc, char **args)
|
|||
{
|
||||
*p++ = ' ';
|
||||
*p++ = '\'';
|
||||
p = grub_script_escape_squotes (p, args[j], grub_strlen (args[j]));
|
||||
p = grub_strchrsub (p, args[j], '\'', "'\\''");
|
||||
*p++ = '\'';
|
||||
}
|
||||
*p++ = '\n';
|
||||
|
|
|
@ -323,16 +323,23 @@ struct legacy_command legacy_commands[] =
|
|||
char *
|
||||
grub_legacy_escape (const char *in, grub_size_t len)
|
||||
{
|
||||
const char *ptr;
|
||||
char saved;
|
||||
char *ptr;
|
||||
char *outptr;
|
||||
int overhead = 0;
|
||||
for (ptr = in; ptr < in + len && *ptr; ptr++)
|
||||
|
||||
for (ptr = (char*)in; ptr < in + len && *ptr; ptr++)
|
||||
if (*ptr == '\'')
|
||||
overhead += 3;
|
||||
outptr = grub_malloc (ptr - in + overhead + 1);
|
||||
if (!outptr)
|
||||
return NULL;
|
||||
grub_script_escape_squotes (outptr, in, len);
|
||||
|
||||
ptr = (char*)in;
|
||||
saved = ptr[len];
|
||||
ptr[len] = '\0';
|
||||
grub_strchrsub (outptr, in, '\'', "'\\''");
|
||||
ptr[len] = saved;
|
||||
return outptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,27 +22,6 @@
|
|||
#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
|
||||
|
|
|
@ -193,6 +193,26 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
|
|||
return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
|
||||
}
|
||||
|
||||
/* Replace all `ch' characters of `input' with `with' and copy the
|
||||
result into `output'; return address of the end in `output'. */
|
||||
static inline char *
|
||||
grub_strchrsub (char *output, const char *input, char ch, const char *with)
|
||||
{
|
||||
grub_size_t grub_strlen (const char *s);
|
||||
while (*input)
|
||||
{
|
||||
if (*input == ch)
|
||||
{
|
||||
grub_strcpy (output, with);
|
||||
output += grub_strlen (with);
|
||||
input++;
|
||||
continue;
|
||||
}
|
||||
*output++ = *input++;
|
||||
}
|
||||
*output = '\0';
|
||||
return output;
|
||||
}
|
||||
|
||||
unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
|
||||
unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);
|
||||
|
|
|
@ -382,9 +382,6 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *c
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue