通用应用程序代码中的数据损坏检测 [英] Data corruption detection in generic app code

查看:75
本文介绍了通用应用程序代码中的数据损坏检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:-D大家好:
我在这里遇到问题,给出了代码片段:

:-D Hi all:
I have a problem here, giving code fragment:

typedef unsigned long HPINDEX; /* Used as a handle */

bool
__ShowWindow(IN HPINDEX hWin)
{
    /*
     * Handle loopup service, converting a handle to
     * a pointer in which we are interested.
     *
     * but all mechnisms exploited here are in user
     * address space, meaning there''s a planty of chances
     * for something to go wrong, any better suggestions?
     */
    WND* pWin = (void*)HpGetSlotByIndex(g_hWinSlotMgr, hWin);

    /*
     * Note that the app simply terminates if pWin is non-null
     * but fabricated by the user.
     */
    if (pWin == 0) {
        /*
         * Invalid hWin.
         */
        return (false);
        }

    /*
     * At this phrase, I confused... :(
     * Assume the pWin is valid, and synchronization is
     * provided.
     *
     * Do I have to check data integrity for the entire
     * WND structure, if a dozen of fields are within,
     * too fancy to comprehend.
     *
     * Letting the native API do the hard part of the
     * work I think is the better way, so we check the
     * result of ShowWindow().
     *
     * What if a malicious intention is made managing
     * to find out the structure and fill it with
     * garbage?
     */

     /*
      * We have to check for validity of hwnd field in
      * the very first call which uses it.
      */
    if (!ShowWindow(pWin->hwnd)) {
        /*
         * Report the user about the data corruption. :(
         * Oh man...
         * Is there any way to detect this error at the
         * beginning of __ShowWindow() WITHOUT calling
         * the native API to do that? thus avoid checking
         * the result of the API?
         */
        }
    /*
     * If Checking the result of ShowWindow() is unavoidable,
     * assuming sync is provided by the user, can I take a
     * breath if we survived it, and blindly think that hwnd
     * will always be valid in any subsquent native invocations?
     */
    UpdateWindow(pWin->hwnd);
}



; P对我的泳池评论表示歉意,
我们应该考虑哪些潜在风险.
欢迎任何建议:)

问候.



;P Apologize for my pool comments,
what potential risks should be considered by us.
any suggestions are welcome:)

Regards.

推荐答案

好,您要完成什么?在您发布的代码中,只要pwnd不为null,就应该行得通.您还担心什么?
Well, what are you trying to accomplish? In the code you''ve posted, as long as pwnd isn''t null, you should be good to go. What else are you concerned about?


我通常会通过调用::IsValidWindow(pWin->hwnd);


这篇关于通用应用程序代码中的数据损坏检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆