Commit ff67da43 authored by Ferenc Wagner's avatar Ferenc Wagner Committed by Alexandre Julliard

Enforce valid tag syntax during input.

parent 05413fcc
...@@ -41,6 +41,8 @@ double progressScale; ...@@ -41,6 +41,8 @@ double progressScale;
*/ */
int progressGroup; int progressGroup;
WNDPROC DefEditProc;
char * char *
renderString (va_list ap) renderString (va_list ap)
{ {
...@@ -319,21 +321,35 @@ guiAsk (va_list ap) ...@@ -319,21 +321,35 @@ guiAsk (va_list ap)
} }
BOOL CALLBACK 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) AskTagProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
int len; int len;
switch (msg) { switch (msg) {
case WM_INITDIALOG:
DefEditProc = (WNDPROC)SetWindowLongPtr
(GetDlgItem (hwnd, IDC_TAG), GWLP_WNDPROC, (LONG_PTR)EditTagProc);
return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD (wParam)) { switch (LOWORD (wParam)) {
case IDOK: case IDOK:
len = GetWindowTextLengthA (GetDlgItem (hwnd, IDC_TAG)); len = GetWindowTextLengthA (GetDlgItem (hwnd, IDC_TAG));
if (len <= MAXTAGLEN) { tag = xmalloc (len+1);
tag = xmalloc (len+1); GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1);
GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1); EndDialog (hwnd, IDOK);
if (!badtagchar (tag)) EndDialog (hwnd, IDOK);
else free (tag);
}
return TRUE; return TRUE;
case IDABORT: case IDABORT:
EndDialog (hwnd, IDABORT); EndDialog (hwnd, IDABORT);
......
...@@ -601,7 +601,7 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, ...@@ -601,7 +601,7 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
if (strlen (tag) > MAXTAGLEN) if (strlen (tag) > MAXTAGLEN)
report (R_FATAL, "tag is too long (maximum %d characters)", report (R_FATAL, "tag is too long (maximum %d characters)",
MAXTAGLEN); MAXTAGLEN);
cp = badtagchar (tag); cp = findbadtagchar (tag);
if (cp) { if (cp) {
report (R_ERROR, "invalid char in tag: %c", *cp); report (R_ERROR, "invalid char in tag: %c", *cp);
usage (); usage ();
......
...@@ -104,15 +104,20 @@ void xprintf (const char *fmt, ...) ...@@ -104,15 +104,20 @@ void xprintf (const char *fmt, ...)
free (buffer); free (buffer);
} }
int
goodtagchar (char c)
{
return (('a'<=c && c<='z') ||
('A'<=c && c<='Z') ||
('0'<=c && c<='9') ||
c=='-' || c=='.');
}
const char * const char *
badtagchar (const char *tag) findbadtagchar (const char *tag)
{ {
while (*tag) while (*tag)
if (('a'<=*tag && *tag<='z') || if (goodtagchar (*tag)) tag++;
('A'<=*tag && *tag<='Z') ||
('0'<=*tag && *tag<='9') ||
*tag=='-' || *tag=='.')
tag++;
else return tag; else return tag;
return NULL; return NULL;
} }
...@@ -33,7 +33,8 @@ void *xrealloc (void *op, size_t len); ...@@ -33,7 +33,8 @@ void *xrealloc (void *op, size_t len);
void xprintf (const char *fmt, ...); void xprintf (const char *fmt, ...);
char *vstrmake (size_t *lenp, va_list ap); char *vstrmake (size_t *lenp, va_list ap);
char *strmake (size_t *lenp, ...); 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); int send_file (const char *name);
......
...@@ -29,7 +29,7 @@ CAPTION "No tag supplied" ...@@ -29,7 +29,7 @@ CAPTION "No tag supplied"
BEGIN BEGIN
CTEXT "Please supply a tag for your report. You can use letters, digits, dashes and periods." CTEXT "Please supply a tag for your report. You can use letters, digits, dashes and periods."
IDC_STATIC, 10, 5, 130, 30 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 DEFPUSHBUTTON "Start", IDOK, 25, 45, 40, 14
PUSHBUTTON "Abort", IDABORT, 85, 45, 40, 14 PUSHBUTTON "Abort", IDABORT, 85, 45, 40, 14
END END
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment