未验证 提交 a41a49a0 编写于 作者: O openharmony_ci 提交者: Gitee

!1429 Done! 995:Add new OpenHarmony 64bits and HDF Coding Guide

Merge pull request !1429 from wusongqing/TR995
此差异已折叠。
# OpenHarmony Java Secure Coding Guide
# Java Secure Coding Guide
This document provides secure coding suggestions for Java-based development.
......@@ -1786,7 +1786,7 @@ public void xsltTrans(String src, String dst, String xslt) {
}
```
A security policy can be added to **TransformerFactory**. Java has a built-in blocklist for XSLT. Here some [insecure methods are disabled by setting **http://javax.xml.XMLConstants/feature/secure-processing** to **true**.](http://javax.xml.xmlconstants/feature/secure-processing属性设置为true开启防护,可以禁用一些不安全的方法。)
A security policy can be added to **TransformerFactory**. Java has a built-in blocklist for XSLT. Here some insecure methods are disabled by setting **http://javax.xml.XMLConstants/feature/secure-processing** to **true**.
## Try best to simplify the regular expression (regex) to prevent regular expression denial of service (ReDoS) attacks
......
# OpenHarmony C&C++ Secure Coding Guide
# C&C++ Secure Coding Guide
This document provides some secure coding suggestions based on the C\&C++ language to guide development.
......
此差异已折叠。
......@@ -8,6 +8,8 @@
- [OpenHarmony Security Design Specifications](OpenHarmony-security-design-guide.md)
- [OpenHarmony Security Design Specifications](OpenHarmony-security-design-guide.md)
### Code Style
Develop, review, and test code following the OpenHarmony coding standards. Make sure code is written in the same style.
......@@ -17,6 +19,8 @@ Develop, review, and test code following the OpenHarmony coding standards. Make
- [JavaScript Coding Style Guide](OpenHarmony-JavaScript-coding-style-guide.md)
- [Python Coding Style Guide](https://pep8.org/)
- [C&C++ Secure Coding Guide](OpenHarmony-c-cpp-secure-coding-guide.md)
- [HDF Driver Coding Guide](OpenHarmony-Java-secure-coding-guide.md)
- [32- and 64-Bit Portability Coding Guide](OpenHarmony-64bits-coding-guide.md)
- [Java Secure Coding Guide](OpenHarmony-Java-secure-coding-guide.md)
- [Logging Guide](OpenHarmony-Log-guide.md)
......@@ -28,6 +32,6 @@ For details, see [Contribution Process](contribution-process.md).
- [Security Issue Handling and Release Processes](https://gitee.com/openharmony/security/blob/master/en/security-process/README.md)
- [OpenHarmony Security and Disclosure Statement](https://gitee.com/openharmony/security/blob/master/en/security-process/security-disclosure.md)
- [OpenHarmony Security Vulnerability Notice](https://gitee.com/openharmony/security/blob/master/en/security-process/security-disclosure.md)
......@@ -7,7 +7,7 @@
OpenHarmony的目标是面向全场景、全连接、全智能时代,基于开源的方式,搭建一个智能终端设备操作系统的框架和平台,促进万物互联产业的繁荣发展。具有“硬件互助,资源共享”、“一次开发,多端部署”、“统一OS,弹性部署”的技术特性。
OpenHarmony支持三种系统类型:
1. 轻量系统(mini system),面向MCU类处理器(例如Arm Cortex-M、RISC-V 32位)的轻量设备,硬件资源极其有限,支持的设备最小内存为128KiB;
1. 轻量系统(mini system),面向MCU类处理器(例如Arm Cortex-M、RISC-V 32位)的轻量设备,硬件资源极其有限,支持的设备最小内存为128KiB;
2. 小型系统(small system),面向应用处理器(例如Arm Cortex-A 64位)的设备,支持的设备最小内存为1MiB
3. 标准系统(standard system),面向应用处理器(例如Arm Cortex-A 64位)的设备,支持的设备最小内存为128MiB
......@@ -35,7 +35,7 @@ OpenHarmony支持三种系统类型:
| size_t | **4** | **8** | **8** | 4 | 8 |
| pointer | **4** | **8** | **8** | 4 | 8 |
上表中只包含了部分基本类型,下表分别将ILP32和LP64的siziof和print`进行对比,展示了更全面的常量和类型对应的差异:
上表中只包含了部分基本类型,下表分别将ILP32和LP64的sizeof和print`进行对比,展示了更全面的常量和类型对应的差异:
| Type | ILP32 sizeof | ILP32 print | LP64 sizeof | LP64 print | 备注 |
| ------------------ | ------------ | ----------- | ----------- | ---------- | ------ |
......@@ -115,8 +115,8 @@ typedef struct tagFoo {
| uint16_t | 2 | 2 | %u | 代替unsigned short |
| int32_t | 4 | 4 | %d | 代替int |
| uint32_t | 4 | 4 | %u | 代替unsigned int |
| int64_t | 8 | 8 | %PRId64 | 代替long long宏实现代码兼容 |
| uint64_t | 8 | 8 | %PRIu64 | 代替unsigned longlong,宏实现代码兼容 |
| int64_t | 8 | 8 | %PRId64 | 代替long long宏实现代码兼容 |
| uint64_t | 8 | 8 | %PRIu64 | 代替unsigned long long、宏实现代码兼容 |
| float | 4 | 4 | %f | 单精度浮点数 |
| double | 8 | 8 | %lf | 双精度浮点数 |
| bool | 1 | 1 | %d | 布尔类型 |
......@@ -170,7 +170,7 @@ long var;
#### 【规则】当需要采用整型变量来存储指针时,变量应该定义成uintptr_t以适应不同的位宽
【说明】uintptr_t类型用于用于存储指针长度级别的数据,其长度在32位和64位可自动适应。
【说明】uintptr_t类型用于用于存储指针长度的数据,其长度在32位和64位可自动适应。
【示例】
......@@ -262,7 +262,7 @@ format ‘%p’ expects argument of type ‘void *’, but argument 2 has type
| 0x80000000LL | 8 | 8 | 增加LL后缀,小于uint32_t范围,长度固定 |
| 0x8000000000 | **NA或8** | **8** | 无后缀,超过uint32_t的范围,编译器默认为LL或无效,64位下固定为uint64_t类型 |
| 0x8000000000L | **NA或8** | **8** | 后缀为L,对超过uint32_t的范围常数,增加该参数没有意义,应当避免使用 |
| 0x8000000000LL | 8 | 8 | 默认为LL,uint64_t类型 |
| 0x8000000000LL | 8 | 8 | 后缀为LL,uint64_t类型 |
从上表中可看出,使用L或UL后缀的常量,其长度在32位和64位下发生变化,不利于代码的可移植性,因此禁止使用这个后缀。
......@@ -533,7 +533,7 @@ q = (int32_t *) (int32_t)&i;
int32_t length = (int32_t)strlen(str); // 错误
```
strlen返回size_t(它在LP64中是unsigned long),当赋值给一个int32_t时,截断是必然发生的。而通常,截断只会在str的长度大于2GB时才会发生,这种情况在程序中一般不会出现,容易出现问题
strlen返回size_t(它在LP64中是unsigned long),当赋值给一个int32_t时,截断是必然发生的。而通常,截断只会在str的长度大于2GB时才会发生,这种情况在程序中一般不会出现,容易忽略
#### 【规则】在64位环境下使用大数组或大for循环索引时,索引类型应当与下标边界保持一致
......
......@@ -16,7 +16,7 @@ HDF(Hardware Driver Foundation)驱动框架,为开发者提供驱动框架
#### 【规则】OpenHarmony的驱动程序,应当使用HDF框架提供的能力实现
【说明】HDF驱动框架提供了驱动加载、驱动服务管理和驱动消息机制,同时还提供了操作系统抽象层(OSAL, Operating System Abstract Layer)和平台抽象层(PAL, Platform Abstract Layer)来保证驱动程序的跨系统跨平台部署的特性。除此之外,HDF提供了驱动模型的抽象、公共工具、外围器件框架等能力。开发者应该基于HDF提供的这些能力开发驱动,从而保证驱动程序可以在各种形态的OpenHarmony上进行部署。
【说明】HDF驱动框架提供了驱动加载、驱动服务管理和驱动消息机制,同时还提供了操作系统抽象层(OSAL, Operating System Abstraction Layer)和平台抽象层(PAL, Platform Abstraction Layer)来保证驱动程序的跨系统跨平台部署的特性。除此之外,HDF提供了驱动模型的抽象、公共工具、外围器件框架等能力。开发者应该基于HDF提供的这些能力开发驱动,从而保证驱动程序可以在各种形态的OpenHarmony上进行部署。
#### 【规则】开发者应当遵循此规范要求,开发能够同时满足内核态和用户态的驱动
......@@ -332,7 +332,7 @@ root {
#### 【建议】当preload字段配置为默认加载时,应当根据业务要求配置按序加载的优先级
【说明】在HDF框架定义的device_info.hcs配置文件中,priority字段(取值范围为整数0到200)是用来表示Host和驱动的优先级。不同的Host内的驱动,Host的priority值越小,驱动加载优先级越高;同一个Host内驱动的priority值越小,加载优先级越高。priority字段的默认值为100,当未配置或字段值相同时,HDF框架将不保证驱动的加载顺序。开发者应当根据业务场景的要求,配置preority字段,保证各个驱动的启动顺序。
【说明】在HDF框架定义的device_info.hcs配置文件中,priority字段(取值范围为整数0到200)是用来表示Host和驱动的优先级。不同的Host内的驱动,Host的priority值越小,驱动加载优先级越高;同一个Host内驱动的priority值越小,加载优先级越高。priority字段的默认值为100,当未配置或字段值相同时,HDF框架将不保证驱动的加载顺序。开发者应当根据业务场景的要求,配置priority字段,保证各个驱动的启动顺序。
【样例】
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册