1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
/*
 * PROJECT:     ReactOS System Control Panel Applet
 * LICENSE:     GPL - See COPYING in the top level directory
 * FILE:        dll/cpl/sysdm/licence.c
 * PURPOSE:     Licence dialog box message handler
 * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
 *
 */

#include "precomp.h"

typedef struct _LIC_CONTEXT
{
    HICON hIcon;
} LIC_CONTEXT, *PLIC_CONTEXT;


static BOOL
OnInitDialog(HWND hDlg, PLIC_CONTEXT pLicInfo)
{
    HRSRC hResInfo;
    HGLOBAL hResMem;
    PCSTR LicenseText;

    pLicInfo->hIcon = LoadImage(hApplet,<--- Null pointer dereference
                                MAKEINTRESOURCE(IDI_CPLSYSTEM),
                                IMAGE_ICON,
                                16,
                                16,
                                0);

    SendMessage(hDlg,
                WM_SETICON,
                ICON_SMALL,
                (LPARAM)pLicInfo->hIcon);

    /* Load license from resource */
    if (!(hResInfo = FindResource(hApplet,
                                  MAKEINTRESOURCE(RC_LICENSE),
                                  MAKEINTRESOURCE(RTDATA))) ||
        !(hResMem = LoadResource(hApplet, hResInfo)) ||
        !(LicenseText = LockResource(hResMem)))
    {
        ShowLastWin32Error(hDlg);
        return FALSE;
    }

    /* Insert the license into the edit control */
    SetDlgItemTextA(hDlg,
                    IDC_LICENCEEDIT,
                    LicenseText);

    PostMessage(GetDlgItem(hDlg, IDC_LICENCEEDIT),
                EM_SETSEL,
                -1,
                0);
    PostMessage(GetDlgItem(hDlg, IDC_LICENCEEDIT), WM_VSCROLL, SB_TOP, 0);
    return TRUE;
}


INT_PTR CALLBACK
LicenceDlgProc(HWND hDlg,
               UINT uMsg,
               WPARAM wParam,
               LPARAM lParam)
{
    PLIC_CONTEXT pLicInfo;

    UNREFERENCED_PARAMETER(lParam);

    pLicInfo = (PLIC_CONTEXT)GetWindowLongPtr(hDlg, DWLP_USER);

    switch (uMsg)
    {
        case WM_INITDIALOG:
            pLicInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LIC_CONTEXT));
            if (pLicInfo == NULL)
            {
                EndDialog(hDlg, 0);
                return FALSE;
            }
            SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pLicInfo);
            return OnInitDialog(hDlg, pLicInfo);<--- Calling function 'OnInitDialog', 2nd argument 'pLicInfo' value is 0

        case WM_DESTROY:
            if (pLicInfo)<--- Assuming that condition 'if(pLicInfo)' is not redundant
            {
                DestroyIcon(pLicInfo->hIcon);
                HeapFree(GetProcessHeap(), 0, pLicInfo);
            }
            break;

        case WM_COMMAND:
            if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
            {
                EndDialog(hDlg,
                          LOWORD(wParam));
                return TRUE;
            }
            break;
    }

    return FALSE;
}