Amiga: tighten input/dialog buffer bounds
Right-size the Intuition string-gadget buffer to BUFSZ so a caller with a BUFSZ-sized buffer cannot be overflowed. Enlarge the amii_yn_function prompt buffer to fit the worst-case query + resp + def + trailing space and switch the appends to Snprintf with remaining-space tracking. Replace sprintf in amii_display_file's "Can't display X: Y" path with Snprintf. In EditColor's Save path drop the strcpy/strcat chain that could trail off the end of oname/nname when dirname returned a near-full path; use Snprintf instead. Rewrite dirname() to copy first and truncate the copy, so it no longer briefly NULs the caller's string.
This commit is contained in:
+9
-6
@@ -339,7 +339,7 @@ struct NewScreen NewHackScreen = { 0, 0, WIDTH, SCREENHEIGHT, 3, 0,
|
|||||||
void
|
void
|
||||||
amii_askname(void)
|
amii_askname(void)
|
||||||
{
|
{
|
||||||
char plnametmp[300]; /* From winreq.c: sizeof(StrStringSIBuff) */
|
char plnametmp[BUFSZ]; /* matches StrStringSIBuff in winreq.c */
|
||||||
*plnametmp = 0;
|
*plnametmp = 0;
|
||||||
do {
|
do {
|
||||||
amii_getlin("Who are you?", plnametmp);
|
amii_getlin("Who are you?", plnametmp);
|
||||||
@@ -577,7 +577,7 @@ amii_yn_function(const char *query, const char *resp, char def)
|
|||||||
char q;
|
char q;
|
||||||
char rtmp[40];
|
char rtmp[40];
|
||||||
boolean digit_ok, allow_num;
|
boolean digit_ok, allow_num;
|
||||||
char prompt[BUFSZ];
|
char prompt[BUFSZ + QBUFSZ + 16];
|
||||||
struct amii_WinDesc *cw;
|
struct amii_WinDesc *cw;
|
||||||
|
|
||||||
if (cw = amii_wins[WIN_MESSAGE])
|
if (cw = amii_wins[WIN_MESSAGE])
|
||||||
@@ -592,10 +592,12 @@ amii_yn_function(const char *query, const char *resp, char def)
|
|||||||
*rb = '\0';
|
*rb = '\0';
|
||||||
(void) strncpy(prompt, query, QBUFSZ - 1);
|
(void) strncpy(prompt, query, QBUFSZ - 1);
|
||||||
prompt[QBUFSZ - 1] = '\0';
|
prompt[QBUFSZ - 1] = '\0';
|
||||||
Sprintf(eos(prompt), " [%s]", respbuf);
|
Snprintf(eos(prompt), sizeof prompt - strlen(prompt),
|
||||||
|
" [%s]", respbuf);
|
||||||
if (def)
|
if (def)
|
||||||
Sprintf(eos(prompt), " (%c)", def);
|
Snprintf(eos(prompt), sizeof prompt - strlen(prompt),
|
||||||
Strcat(prompt, " ");
|
" (%c)", def);
|
||||||
|
Snprintf(eos(prompt), sizeof prompt - strlen(prompt), " ");
|
||||||
pline("%s", prompt);
|
pline("%s", prompt);
|
||||||
} else {
|
} else {
|
||||||
amii_putstr(WIN_MESSAGE, 0, query);
|
amii_putstr(WIN_MESSAGE, 0, query);
|
||||||
@@ -705,7 +707,8 @@ amii_display_file(const char *fn, boolean complain)
|
|||||||
|
|
||||||
if ((fp = dlb_fopen(fn, RDTMODE)) == (dlb *) NULL) {
|
if ((fp = dlb_fopen(fn, RDTMODE)) == (dlb *) NULL) {
|
||||||
if (complain) {
|
if (complain) {
|
||||||
sprintf(buf, "Can't display %s: %s", fn, strerror(errno));
|
Snprintf(buf, sizeof buf,
|
||||||
|
"Can't display %s: %s", fn, strerror(errno));
|
||||||
amii_addtopl(buf);
|
amii_addtopl(buf);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
+28
-20
@@ -21,8 +21,8 @@ struct IntuiText IText1 = { 3, 0, JAM1, 4, 1, NULL, (UBYTE *) "Cancel",
|
|||||||
struct Gadget Gadget2 = { NULL, 9, 15, 56, 10, NULL, RELVERIFY, BOOLGADGET,
|
struct Gadget Gadget2 = { NULL, 9, 15, 56, 10, NULL, RELVERIFY, BOOLGADGET,
|
||||||
(APTR) &Border1, NULL, &IText1, NULL, NULL, 1,
|
(APTR) &Border1, NULL, &IText1, NULL, NULL, 1,
|
||||||
NULL };
|
NULL };
|
||||||
UBYTE StrStringSIBuff[300];
|
UBYTE StrStringSIBuff[BUFSZ];
|
||||||
struct StringInfo StrStringSInfo = { StrStringSIBuff, UNDOBUFFER, 0, 300, 0,
|
struct StringInfo StrStringSInfo = { StrStringSIBuff, UNDOBUFFER, 0, BUFSZ, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, NULL };
|
0, 0, 0, 0, 0, 0, 0, NULL };
|
||||||
SHORT BorderVectors2[] = { 0, 0, 439, 0, 439, 11, 0, 11, 0, 0 };
|
SHORT BorderVectors2[] = { 0, 0, 439, 0, 439, 11, 0, 11, 0, 0 };
|
||||||
struct Border Border2 = { -1, -1, 3, 0, JAM1, 5, BorderVectors2, NULL };
|
struct Border Border2 = { -1, -1, 3, 0, JAM1, 5, BorderVectors2, NULL };
|
||||||
@@ -187,14 +187,23 @@ EditColor(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(oname, dirname((char *) configfile));
|
{
|
||||||
if (oname[strlen(oname) - 1] != ':') {
|
size_t olen;
|
||||||
sprintf(nname, "%s/New_NetHack.cnf", oname);
|
strncpy(oname, dirname((char *) configfile),
|
||||||
strcat(oname, "/");
|
sizeof(oname) - 1);
|
||||||
strcat(oname, "Old_NetHack.cnf");
|
oname[sizeof(oname) - 1] = '\0';
|
||||||
} else {
|
olen = strlen(oname);
|
||||||
sprintf(nname, "%sNew_NetHack.cnf", oname);
|
if (olen > 0 && oname[olen - 1] != ':') {
|
||||||
strcat(oname, "Old_NetHack.cnf");
|
Snprintf(nname, sizeof nname,
|
||||||
|
"%s/New_NetHack.cnf", oname);
|
||||||
|
Snprintf(oname + olen, sizeof(oname) - olen,
|
||||||
|
"/Old_NetHack.cnf");
|
||||||
|
} else {
|
||||||
|
Snprintf(nname, sizeof nname,
|
||||||
|
"%sNew_NetHack.cnf", oname);
|
||||||
|
Snprintf(oname + olen, sizeof(oname) - olen,
|
||||||
|
"Old_NetHack.cnf");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nfp = fopen(nname, "w");
|
nfp = fopen(nname, "w");
|
||||||
@@ -506,20 +515,19 @@ EditClipping(void)
|
|||||||
char *
|
char *
|
||||||
dirname(char *str)
|
dirname(char *str)
|
||||||
{
|
{
|
||||||
char *t, c;
|
|
||||||
static char dir[300];
|
static char dir[300];
|
||||||
|
char *t;
|
||||||
|
|
||||||
t = strrchr(str, '/');
|
strncpy(dir, str, sizeof(dir) - 1);
|
||||||
|
dir[sizeof(dir) - 1] = '\0';
|
||||||
|
|
||||||
|
t = strrchr(dir, '/');
|
||||||
|
if (!t)
|
||||||
|
t = strrchr(dir, ':');
|
||||||
if (!t)
|
if (!t)
|
||||||
t = strrchr(str, ':');
|
|
||||||
if (!t) {
|
|
||||||
dir[0] = '\0';
|
dir[0] = '\0';
|
||||||
} else {
|
else
|
||||||
c = *t;
|
*t = '\0';
|
||||||
*t = 0;
|
|
||||||
strcpy(dir, str);
|
|
||||||
*t = c;
|
|
||||||
}
|
|
||||||
return (dir);
|
return (dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user