arogue5: close security holes.
Prevent whoami (player name), file_name, and score_file from being changed if the systemwide save location is being used.
This commit is contained in:
parent
4c16144c6b
commit
5ce56875ec
3 changed files with 49 additions and 14 deletions
|
|
@ -92,7 +92,7 @@ char **envp;
|
||||||
if ((env = getenv("ROGUEOPTS")) != NULL)
|
if ((env = getenv("ROGUEOPTS")) != NULL)
|
||||||
parse_opts(env);
|
parse_opts(env);
|
||||||
|
|
||||||
if (whoami[0] == '\0')
|
if (!use_savedir && whoami[0] == '\0')
|
||||||
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
||||||
|
|
||||||
if (env == NULL || fruit[0] == '\0') {
|
if (env == NULL || fruit[0] == '\0') {
|
||||||
|
|
@ -194,16 +194,19 @@ char **envp;
|
||||||
byebye(-1);
|
byebye(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((whoami == NULL) || (*whoami == '\0') || (strcmp(whoami,"dosuser")==0))
|
if (!use_savedir) {
|
||||||
{
|
if ((whoami == NULL) || (*whoami == '\0') ||
|
||||||
echo();
|
(strcmp(whoami,"dosuser")==0))
|
||||||
mvaddstr(23,2,"Rogue's Name? ");
|
{
|
||||||
wgetnstr(stdscr,whoami,LINELEN);
|
echo();
|
||||||
noecho();
|
mvaddstr(23,2,"Rogue's Name? ");
|
||||||
}
|
wgetnstr(stdscr,whoami,LINELEN);
|
||||||
|
noecho();
|
||||||
|
}
|
||||||
|
|
||||||
if ((whoami == NULL) || (*whoami == '\0'))
|
if ((whoami == NULL) || (*whoami == '\0'))
|
||||||
strcpy(whoami,"Rodney");
|
strcpy(whoami,"Rodney");
|
||||||
|
}
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ int put_bool(),
|
||||||
get_bool(),
|
get_bool(),
|
||||||
put_str(),
|
put_str(),
|
||||||
get_str(),
|
get_str(),
|
||||||
|
get_restr(),
|
||||||
put_abil(),
|
put_abil(),
|
||||||
get_abil(),
|
get_abil(),
|
||||||
get_quest(),
|
get_quest(),
|
||||||
|
|
@ -57,19 +58,34 @@ OPTION optlist[] = {
|
||||||
{"pickup", "Pick things up automatically: ",
|
{"pickup", "Pick things up automatically: ",
|
||||||
(int *) &auto_pickup, put_bool, get_bool },
|
(int *) &auto_pickup, put_bool, get_bool },
|
||||||
{"name", "Name: ",
|
{"name", "Name: ",
|
||||||
(int *) whoami, put_str, get_str },
|
(int *) whoami, put_str, get_restr },
|
||||||
{"fruit", "Fruit: ",
|
{"fruit", "Fruit: ",
|
||||||
(int *) fruit, put_str, get_str },
|
(int *) fruit, put_str, get_str },
|
||||||
{"file", "Save file: ",
|
{"file", "Save file: ",
|
||||||
(int *) file_name, put_str, get_str },
|
(int *) file_name, put_str, get_restr },
|
||||||
{"score", "Score file: ",
|
{"score", "Score file: ",
|
||||||
(int *) score_file, put_str, get_str },
|
(int *) score_file, put_str, get_restr },
|
||||||
{"class", "Character class: ",
|
{"class", "Character class: ",
|
||||||
(int *)&char_type, put_abil, get_abil },
|
(int *)&char_type, put_abil, get_abil },
|
||||||
{"quest", "Quest item: ",
|
{"quest", "Quest item: ",
|
||||||
(int *) &quest_item, put_quest, get_quest }
|
(int *) &quest_item, put_quest, get_quest }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* For fields that would be restricted if use_savedir is set. */
|
||||||
|
int get_restr(char *optstr, WINDOW *win)
|
||||||
|
{
|
||||||
|
int oy, ox;
|
||||||
|
|
||||||
|
if (use_savedir)
|
||||||
|
{
|
||||||
|
getyx(win, oy, ox);
|
||||||
|
put_str(optstr, win);
|
||||||
|
return get_ro(win, oy, ox);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return get_str(optstr, win);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ability field is read-only
|
* The ability field is read-only
|
||||||
*/
|
*/
|
||||||
|
|
@ -343,6 +359,11 @@ register char *str;
|
||||||
* Look it up and deal with it
|
* Look it up and deal with it
|
||||||
*/
|
*/
|
||||||
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
|
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
|
||||||
|
/* None of these can be changed if using system savefiles. */
|
||||||
|
if (use_savedir && (!strcmp(op->o_name, "name") ||
|
||||||
|
!strcmp(op->o_name, "file") ||
|
||||||
|
!strcmp(op->o_name, "score") ))
|
||||||
|
continue;
|
||||||
if (EQSTR(str, op->o_name, len))
|
if (EQSTR(str, op->o_name, len))
|
||||||
{
|
{
|
||||||
if (op->o_putfunc == put_bool) /* if option is a boolean */
|
if (op->o_putfunc == put_bool) /* if option is a boolean */
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,10 @@ save_game()
|
||||||
mpos = 0;
|
mpos = 0;
|
||||||
if (file_name[0] != '\0')
|
if (file_name[0] != '\0')
|
||||||
{
|
{
|
||||||
msg("Save file (%s)? ", file_name);
|
if (use_savedir)
|
||||||
|
msg("Save game? ");
|
||||||
|
else
|
||||||
|
msg("Save file (%s)? ", file_name);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = readchar();
|
c = readchar();
|
||||||
|
|
@ -53,6 +56,10 @@ save_game()
|
||||||
msg("File name: %s", file_name);
|
msg("File name: %s", file_name);
|
||||||
goto gotfile;
|
goto gotfile;
|
||||||
}
|
}
|
||||||
|
if (use_savedir) {
|
||||||
|
msg("");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|
@ -69,7 +76,11 @@ save_game()
|
||||||
strcpy(file_name, buf);
|
strcpy(file_name, buf);
|
||||||
gotfile:
|
gotfile:
|
||||||
if ((savef = fopen(file_name, "w")) == NULL)
|
if ((savef = fopen(file_name, "w")) == NULL)
|
||||||
|
{
|
||||||
msg(strerror(errno)); /* fake perror() */
|
msg(strerror(errno)); /* fake perror() */
|
||||||
|
if (use_savedir)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
} while (savef == NULL);
|
} while (savef == NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue