简体   繁体   English

Golang 加密消息修复 go-crypt()

[英]Golang encrypt message Fix go-crypt()

package main

import(

crypt "github.com/amoghe/go-crypt"
) 

Running the code above gives err:运行上面的代码给出错误:

root@kali:~/Desktop/tools/gos/SUnix# go run crack.go

 github.com/amoghe/go-crypt
/root/go/pkg/mod/github.com/amoghe/go-crypt@v0.0.0-20191109212615-b2ff80594b7f/crypt_r.go: In function ‘gnu_ext_crypt’:
/root/go/pkg/mod/github.com/amoghe/go-crypt@v0.0.0-20191109212615-b2ff80594b7f/crypt_r.go:35:3: warning: 'strncpy' specified bound depends on the length of the source argument...

this is bad image, how can I fix it这是不好的图像,我该如何修复它

This warning is printed by the C compiler (the file crypt_r.go includes inline code in the C language) to warn the author/users that the code includes a potential issue.此警告由 C 编译器打印(文件crypt_r.go包含 C 语言中的内联代码),以警告作者/用户该代码包含潜在问题。 In this case the warning can be safely ignored but if you want it fixed it's probably best to raise a PR/issue on the appropriate repository .在这种情况下,可以安全地忽略警告,但如果您想修复它,最好在适当的存储库上提出 PR/问题。

warning 'strncpy' specified bound depends on the length of the source argument means that it's bad practice to base the length of a string copy on the length of the source; warning 'strncpy' specified bound depends on the length of the source argument意味着将字符串副本的长度基于源的长度是不好的做法; if you do this and the source is longer than the destination buffer then you have a buffer overflow which is bad!.如果你这样做并且源比目标缓冲区长,那么你有一个缓冲区溢出,这是不好的!。 However in this case the destination buffer is created on the line above the strncpy so it's unlikely to be an issue (unless the allocation fails for some reason).但是,在这种情况下,目标缓冲区是在strncpy上方的行上创建的,因此不太可能成为问题(除非由于某种原因分配失败)。

This kind of thing can cause real issues in applications written in C (and many other languages);这种事情可能会导致用 C(和许多其他语言)编写的应用程序出现实际问题; fortunately go protects you (it will panic rather than overwrite the buffer) unless you use the unsafe package (or include C code!).幸运的是,除非您使用 unsafe 包(或包含 C 代码!),否则 go 会保护您(它会恐慌而不是覆盖缓冲区)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM