Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of C language Network programming and Cross-platform Code Security

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What this article shares with you is an example analysis of C language network programming and cross-platform code security. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.

C language is simple in grammar, but rich in connotation. For a smart person, it may take a few hours to learn to use the C language, but it may be difficult for a generation to become a master. C language hides traps everywhere, does not read a large number of excellent code, does not think about the special features of master expert code, does not write a large number of applications, and is often easy to inadvertently hide mines in the program. Once it breaks out, the system is blown up beyond recognition.

This is an excerpt from the code research in the system of a well-known company.

1. Shift trap

Daniel used the following methods when writing a base64 codec program:

Staticvoid encodeblock (unsigned char * in, unsigned char * out, int len)

{

Out [0] = (unsigned char) cb64 [(int) (in [0] > > 2)]

Out [1] = (unsigned char) cb64 [(int) ((in [0] & 0x03) > 4)]

Out [2] = (unsigned char) (len > 1? Cb64 [(int) (in [1] & 0x0f) > 6))]:'=')

Out [3] = (unsigned char) (len > 2? Cb64 [(int) (in [2] & 0x3f)]:'=')

}

This is good in this system, but it hides a lot of risks. The system is used as a basic encryption tool for a variety of embedded devices, and there is an array of out-of-line mines hidden here. (int) (in [0] > > 2) if not & 0x3f, after the right shift in different compiler environments, some blank pulls on the left are filled with zero, some are filled with 1, and some are filled with the highest symbol bit, which will lead to the non-availability of data in the encryption of different systems, and sometimes overflow.

two。 Align traps

Sizeof is a method often used in C language, and some people classify it as an operator. It is quite convenient for him to calculate the pointer offset of structural body variables. Many books recommend it, because he can automatically calculate and adjust the basic type variables according to different systems and compilers, and has strong adaptability and cross-platform ability, but this self-adaptation is very strong in stand-alone programs, but when different systems interact. There will be data inconsistencies. Different systems or programming languages will convert the same structure into different byte streams, in which case the data transfer interaction will lose consistency. And our system uses C language, java as the client, while java has no structure and can only self-assemble the members of the object according to the system size. The C language veteran suggested that I adapt the C system on the java side and do a similar C structure alignment operation on the java side. This is a very complicated project. Don't guess whether the C side is two-byte alignment or four-byte alignment. It is impossible to adapt to different C devices.

The above is an example analysis of C language network programming and cross-platform code security. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report