CWE --- NULL Pointer Dereference -- 例子
来源:互联网 发布:格林数据 编辑:程序博客网 时间:2024/05/16 15:56
原文地址:
https://cwe.mitre.org/data/definitions/476.html
Description Summary
Extended Description
NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions
Example 1
While there are no complete fixes aside from conscientious programming, the following steps will go a long way to ensure that NULL pointer dereferences do not occur.
If you are working with a multithreaded or otherwise asynchronous environment, ensure that proper locking APIs are used to lock before the if statement; and unlock when it has finished.
Example 2
This example takes an IP address from a user, verifies that it is well formed and then looks up the hostname and copies it into a buffer.
If an attacker provides an address that appears to be well-formed, but the address does not resolve to a hostname, then the call to gethostbyaddr() will return NULL. Since the code does not check the return value from gethostbyaddr (CWE-252), a NULL pointer dereference would then occur in the call to strcpy().
Note that this example is also vulnerable to a buffer overflow (see CWE-119).
Example 3
In the following code, the programmer assumes that the system always has a property named "cmd" defined. If an attacker can control the program's environment so that "cmd" is not defined, the program throws a NULL pointer exception when it attempts to call the trim() method.
Example 4
This application has registered to handle a URL when sent an intent:
The application assumes the URL will always be included in the intent. When the URL is not present, the call to getStringExtra() will return null, thus causing a null pointer exception when length() is called.
- CWE --- NULL Pointer Dereference -- 例子
- Unable to handle kernel NULL pointer dereference.
- Unable to handle kernel NULL pointer dereference.
- CWE -- 不要误用 sizeof (pointer) -- 例子
- 介绍Unable to handle kernel NULL pointer dereference...
- unable to handle kernel null pointer dereference at virtual address
- 解决Unable to handle kernel NULL pointer dereference
- Kernel OOPS: BUG: unable to handle kernel NULL pointer dereference
- oops 消息 Unable to handle kernel NULL pointer dereference at virtual address
- Unable to handle kernel NULL pointer dereference at virtual address-----------原因分析 ,及解决办法
- 操作寄存器错误Unable to handle kernel NULL pointer dereference at virtual address的解决办法
- Oops: Unable to handle kernel NULL pointer dereference at virtual address 00000004
- KERNEL BUG: unable to handle kernel NULL pointer dereference at 00000004
- Unable to handle kernel NULL pointer dereference at virtual address 0000错误解决
- oops 消息 Unable to handle kernel NULL pointer dereference at virtual address .
- Unable to handle kernel NULL pointer dereference at virtual address 00000058的错误解决
- oops 消息 Unable to handle kernel NULL pointer dereference at virtual address
- Unable to handle kernel NULL pointer dereference at virtual address 00000000问题的解决
- [go] 环境变量相关 GOROOT GOPATH PATH
- windows环境安装zookeeper图文讲解
- 脚本获取自身ip
- [转帖] 一些算法刷题的网站
- keystone创建service entity和API endpoint
- CWE --- NULL Pointer Dereference -- 例子
- 551. Student Attendance Record I
- linux下sftp上传下载命令
- LDR的用法(ARM指令及伪指令)
- 标准投资回收期
- C语言结构体内存分配——字节码对齐
- 磁疗是不是真的?磁场疗法能促使入睡的实验研究
- php基础语法
- PostgreSQL的数据文件构成