mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-13 01:08:45 +00:00
Avoid possible overruns by dinamically allocating the required buffer.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@33499 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
18b02464b4
commit
67ab913033
@ -30,8 +30,9 @@ void convert_to_full_posix_path(char const * from, char *to)
|
|||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
char buf[2 * PATH_MAX];
|
char * buf;
|
||||||
char posixpath[PATH_MAX + 1];
|
int bufsize;
|
||||||
|
char posixpath[PATH_MAX];
|
||||||
|
|
||||||
if (ac < 3 || ac > 4) {
|
if (ac < 3 || ac > 4) {
|
||||||
MessageBox(0, "Usage: lyxeditor [-g] <file.tex> <lineno>",
|
MessageBox(0, "Usage: lyxeditor [-g] <file.tex> <lineno>",
|
||||||
@ -40,14 +41,24 @@ int main(int ac, char **av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ac == 3) {
|
if (ac == 3) {
|
||||||
|
char const * fmt = "lyxeditor.sh" PROGRAM_SUFFIX " '%s' %s";
|
||||||
convert_to_full_posix_path(av[1], posixpath);
|
convert_to_full_posix_path(av[1], posixpath);
|
||||||
sprintf(buf, "lyxeditor.sh" PROGRAM_SUFFIX " '%s' %s",
|
bufsize = snprintf(0, 0, fmt, posixpath, av[2]) + 1;
|
||||||
posixpath, av[2]);
|
if ((buf = malloc(bufsize)))
|
||||||
|
snprintf(buf, bufsize, fmt, posixpath, av[2]);
|
||||||
} else {
|
} else {
|
||||||
|
char const * fmt = "lyxclient" PROGRAM_SUFFIX " %s '%s' %s";
|
||||||
convert_to_full_posix_path(av[2], posixpath);
|
convert_to_full_posix_path(av[2], posixpath);
|
||||||
sprintf(buf, "lyxclient" PROGRAM_SUFFIX " %s '%s' %s",
|
bufsize = snprintf(0, 0, fmt, av[1], posixpath, av[3]) + 1;
|
||||||
av[1], posixpath, av[3]);
|
if ((buf = malloc(bufsize)))
|
||||||
|
snprintf(buf, bufsize, fmt, av[1], posixpath, av[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!buf) {
|
||||||
|
MessageBox(0, "Too long arguments", "lyxeditor", 0);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
system(buf);
|
system(buf);
|
||||||
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user