[CPL] Boundary check of Control Panel applets (#4706)

- Check the boundary (i < NUM_APPLETS) of the variable i in CPlApplet functions.
- Use UINT type for the variable i.
This commit is contained in:
Katayama Hirofumi MZ 2022-09-17 13:59:51 +09:00 committed by GitHub
parent 37ccb9e594
commit e5ebbc8afa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 194 additions and 98 deletions

View file

@ -240,7 +240,7 @@ CPlApplet(HWND hwndCPl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
INT i = (INT)lParam1; UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
@ -251,6 +251,7 @@ CPlApplet(HWND hwndCPl,
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
if (i < NUM_APPLETS)
{ {
CPLINFO *CPlInfo = (CPLINFO*)lParam2; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0; CPlInfo->lData = 0;
@ -258,14 +259,23 @@ CPlApplet(HWND hwndCPl,
CPlInfo->idName = Applets[i].idName; CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idInfo = Applets[i].idDescription;
} }
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;

View file

@ -252,7 +252,7 @@ cleanup:
LONG CALLBACK LONG CALLBACK
CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2) CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{ {
int i = (int)lParam1; UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
@ -263,6 +263,7 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
if (i < NUM_APPLETS)
{ {
CPLINFO *CPlInfo = (CPLINFO*)lParam2; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0; CPlInfo->lData = 0;
@ -270,14 +271,23 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
CPlInfo->idName = Applets[i].idName; CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idInfo = Applets[i].idDescription;
} }
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;

View file

@ -548,6 +548,7 @@ CPlApplet(
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
if (i < NUM_APPLETS)
{ {
CPLINFO *CPlInfo = (CPLINFO*)lParam2; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0; CPlInfo->lData = 0;
@ -555,14 +556,23 @@ CPlApplet(
CPlInfo->idName = Applets[i].idName; CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idInfo = Applets[i].idDescription;
} }
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;
} }

View file

@ -87,9 +87,7 @@ LONG CALLBACK
CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2) CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{ {
CPLINFO *CPlInfo; CPLINFO *CPlInfo;
int i; UINT i = (UINT)lParam1;
i = (int)lParam1;
switch (uMsg) switch (uMsg)
{ {
@ -100,15 +98,25 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
CPlInfo = (CPLINFO*)lParam2; if (i < NUM_APPLETS)
CPlInfo->lData = 0; {
CPlInfo->idIcon = Applets[i].idIcon; CPlInfo = (CPLINFO*)lParam2;
CPlInfo->idName = Applets[i].idName; CPlInfo->lData = 0;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription;
}
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
} }

View file

@ -232,6 +232,8 @@ CPlApplet(HWND hwndCpl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
case CPL_INIT: case CPL_INIT:
@ -241,23 +243,31 @@ CPlApplet(HWND hwndCpl,
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
{ if (i < NUM_APPLETS)
CPLINFO *CPlInfo = (CPLINFO*)lParam2; {
UINT uAppIndex = (UINT)lParam1; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0;
CPlInfo->lData = 0; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idIcon = Applets[uAppIndex].idIcon; CPlInfo->idName = Applets[i].idName;
CPlInfo->idName = Applets[uAppIndex].idName; CPlInfo->idInfo = Applets[i].idDescription;
CPlInfo->idInfo = Applets[uAppIndex].idDescription; }
else
{
return TRUE;
}
break; break;
}
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[(UINT)lParam1].AppletProc(hwndCpl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[(UINT)lParam1].AppletProc(hwndCpl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;

View file

@ -319,11 +319,9 @@ LONG CALLBACK
CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2) CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{ {
CPLINFO *CPlInfo; CPLINFO *CPlInfo;
DWORD i; UINT i = (UINT)lParam1;
UNREFERENCED_PARAMETER(hwndCPl); UNREFERENCED_PARAMETER(hwndCPl);
i = (DWORD)lParam1;
switch (uMsg) switch (uMsg)
{ {
case CPL_INIT: case CPL_INIT:
@ -333,15 +331,25 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
CPlInfo = (CPLINFO*)lParam2; if (i < NUM_APPLETS)
CPlInfo->lData = 0; {
CPlInfo->idIcon = Applets[i].idIcon; CPlInfo = (CPLINFO*)lParam2;
CPlInfo->idName = Applets[i].idName; CPlInfo->lData = 0;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription;
}
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
} }

View file

@ -87,6 +87,8 @@ CPlApplet(HWND hwndCpl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
UINT i = (UINT)lParam1;
switch(uMsg) switch(uMsg)
{ {
case CPL_INIT: case CPL_INIT:
@ -96,26 +98,31 @@ CPlApplet(HWND hwndCpl,
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
{ if (i < NUM_APPLETS)
CPLINFO *CPlInfo = (CPLINFO*)lParam2; {
UINT uAppIndex = (UINT)lParam1; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = lParam1;
CPlInfo->lData = lParam1; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idIcon = Applets[uAppIndex].idIcon; CPlInfo->idName = Applets[i].idName;
CPlInfo->idName = Applets[uAppIndex].idName; CPlInfo->idInfo = Applets[i].idDescription;
CPlInfo->idInfo = Applets[uAppIndex].idDescription; }
else
{
return TRUE;
}
break; break;
}
case CPL_DBLCLK: case CPL_DBLCLK:
{ if (i < NUM_APPLETS)
UINT uAppIndex = (UINT)lParam1; Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2); else
return TRUE;
break; break;
}
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[(UINT)lParam1].AppletProc(hwndCpl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;

View file

@ -745,6 +745,8 @@ CPlApplet(HWND hwndCpl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
case CPL_INIT: case CPL_INIT:
@ -754,29 +756,31 @@ CPlApplet(HWND hwndCpl,
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
{ if (i < NUM_APPLETS)
CPLINFO *CPlInfo = (CPLINFO*)lParam2; {
UINT uAppIndex = (UINT)lParam1; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0;
CPlInfo->lData = 0; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idIcon = Applets[uAppIndex].idIcon; CPlInfo->idName = Applets[i].idName;
CPlInfo->idName = Applets[uAppIndex].idName; CPlInfo->idInfo = Applets[i].idDescription;
CPlInfo->idInfo = Applets[uAppIndex].idDescription; }
else
{
return TRUE;
}
break; break;
}
case CPL_DBLCLK: case CPL_DBLCLK:
{ if (i < NUM_APPLETS)
UINT uAppIndex = (UINT)lParam1; Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
Applets[uAppIndex].AppletProc(hwndCpl, else
uMsg, return TRUE;
lParam1,
lParam2);
break; break;
}
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[(UINT)lParam1].AppletProc(hwndCpl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;

View file

@ -155,7 +155,7 @@ CPlApplet(HWND hwndCPl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
int i = (int)lParam1; UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
@ -170,20 +170,26 @@ CPlApplet(HWND hwndCPl,
} }
case CPL_INQUIRE: case CPL_INQUIRE:
{ if (i < NUM_APPLETS)
CPLINFO *CPlInfo = (CPLINFO*)lParam2; {
CPlInfo->lData = 0; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->idIcon = Applets[i].idIcon; CPlInfo->lData = 0;
CPlInfo->idName = Applets[i].idName; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription;
}
else
{
return TRUE;
}
break; break;
}
case CPL_DBLCLK: case CPL_DBLCLK:
{ if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
}
} }
return FALSE; return FALSE;

View file

@ -203,7 +203,7 @@ CPlApplet(HWND hwndCPl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
INT i = (INT)lParam1; UINT i = (UINT)lParam1;
UNREFERENCED_PARAMETER(hwndCPl); UNREFERENCED_PARAMETER(hwndCPl);
@ -216,6 +216,7 @@ CPlApplet(HWND hwndCPl,
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
if (i < NUM_APPLETS)
{ {
CPLINFO *CPlInfo = (CPLINFO*)lParam2; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0; CPlInfo->lData = 0;
@ -223,15 +224,23 @@ CPlApplet(HWND hwndCPl,
CPlInfo->idName = Applets[i].idName; CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idInfo = Applets[i].idDescription;
} }
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
case CPL_STARTWPARMSW: case CPL_STARTWPARMSW:
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
break;
} }
return FALSE; return FALSE;

View file

@ -131,7 +131,7 @@ CPlApplet(HWND hwndCpl,
LPARAM lParam1, LPARAM lParam1,
LPARAM lParam2) LPARAM lParam2)
{ {
INT i = (INT)lParam1; UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
@ -142,20 +142,26 @@ CPlApplet(HWND hwndCpl,
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
{ if (i < NUM_APPLETS)
CPLINFO *CPlInfo = (CPLINFO*)lParam2; {
CPlInfo->lData = 0; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->idIcon = Applets[i].idIcon; CPlInfo->lData = 0;
CPlInfo->idName = Applets[i].idName; CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idName = Applets[i].idName;
} CPlInfo->idInfo = Applets[i].idDescription;
break; }
else
{
return TRUE;
}
break;
case CPL_DBLCLK: case CPL_DBLCLK:
{ if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2); Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
} else
break; return TRUE;
break;
} }
return FALSE; return FALSE;
} }

View file

@ -90,7 +90,7 @@ UsrmgrApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
LONG CALLBACK LONG CALLBACK
CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2) CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{ {
int i = (int)lParam1; UINT i = (UINT)lParam1;
switch (uMsg) switch (uMsg)
{ {
@ -101,6 +101,7 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
return NUM_APPLETS; return NUM_APPLETS;
case CPL_INQUIRE: case CPL_INQUIRE:
if (i < NUM_APPLETS)
{ {
CPLINFO *CPlInfo = (CPLINFO*)lParam2; CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0; CPlInfo->lData = 0;
@ -108,10 +109,17 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
CPlInfo->idName = Applets[i].idName; CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription; CPlInfo->idInfo = Applets[i].idDescription;
} }
else
{
return TRUE;
}
break; break;
case CPL_DBLCLK: case CPL_DBLCLK:
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2); if (i < NUM_APPLETS)
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
else
return TRUE;
break; break;
} }