Enforce valid tag syntax during input.

This commit is contained in:
Ferenc Wagner 2005-04-18 09:54:24 +00:00 committed by Alexandre Julliard
parent 05413fccc5
commit ff67da4321
5 changed files with 37 additions and 15 deletions

View File

@ -41,6 +41,8 @@ double progressScale;
*/
int progressGroup;
WNDPROC DefEditProc;
char *
renderString (va_list ap)
{
@ -318,22 +320,36 @@ guiAsk (va_list ap)
return ret;
}
BOOL CALLBACK
EditTagProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_CHAR:
if (wParam == 8) break; /* backspace is OK */
if (GetWindowTextLengthA (hwnd) == MAXTAGLEN ||
!goodtagchar (wParam)) return TRUE;
break;
}
return CallWindowProcA (DefEditProc, hwnd, msg, wParam, lParam);
}
BOOL CALLBACK
AskTagProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int len;
switch (msg) {
case WM_INITDIALOG:
DefEditProc = (WNDPROC)SetWindowLongPtr
(GetDlgItem (hwnd, IDC_TAG), GWLP_WNDPROC, (LONG_PTR)EditTagProc);
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam)) {
case IDOK:
len = GetWindowTextLengthA (GetDlgItem (hwnd, IDC_TAG));
if (len <= MAXTAGLEN) {
tag = xmalloc (len+1);
GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1);
if (!badtagchar (tag)) EndDialog (hwnd, IDOK);
else free (tag);
}
tag = xmalloc (len+1);
GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1);
EndDialog (hwnd, IDOK);
return TRUE;
case IDABORT:
EndDialog (hwnd, IDABORT);

View File

@ -601,7 +601,7 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
if (strlen (tag) > MAXTAGLEN)
report (R_FATAL, "tag is too long (maximum %d characters)",
MAXTAGLEN);
cp = badtagchar (tag);
cp = findbadtagchar (tag);
if (cp) {
report (R_ERROR, "invalid char in tag: %c", *cp);
usage ();

View File

@ -104,15 +104,20 @@ void xprintf (const char *fmt, ...)
free (buffer);
}
int
goodtagchar (char c)
{
return (('a'<=c && c<='z') ||
('A'<=c && c<='Z') ||
('0'<=c && c<='9') ||
c=='-' || c=='.');
}
const char *
badtagchar (const char *tag)
findbadtagchar (const char *tag)
{
while (*tag)
if (('a'<=*tag && *tag<='z') ||
('A'<=*tag && *tag<='Z') ||
('0'<=*tag && *tag<='9') ||
*tag=='-' || *tag=='.')
tag++;
if (goodtagchar (*tag)) tag++;
else return tag;
return NULL;
}

View File

@ -33,7 +33,8 @@ void *xrealloc (void *op, size_t len);
void xprintf (const char *fmt, ...);
char *vstrmake (size_t *lenp, va_list ap);
char *strmake (size_t *lenp, ...);
const char *badtagchar (const char *tag);
int goodtagchar (char c);
const char *findbadtagchar (const char *tag);
int send_file (const char *name);

View File

@ -29,7 +29,7 @@ CAPTION "No tag supplied"
BEGIN
CTEXT "Please supply a tag for your report. You can use letters, digits, dashes and periods."
IDC_STATIC, 10, 5, 130, 30
EDITTEXT IDC_TAG, 35, 30, 80, 10
EDITTEXT IDC_TAG, 35, 30, 80, 10, ES_AUTOHSCROLL
DEFPUSHBUTTON "Start", IDOK, 25, 45, 40, 14
PUSHBUTTON "Abort", IDABORT, 85, 45, 40, 14
END