简体   繁体   English

$符号导致程序崩溃

[英]$ symbol causes program to crash

Here is my program: 这是我的程序:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
int main()
{
    std::string hash = crypt("asd123","$2a$13$IP4FT4gf123I5bT6o4123123123123nbEXFqo.Oa123");
    std::cout << hash;
}

Running this causes the error 运行此会导致错误

terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not valid Aborted (core dumped) 引发'std :: logic_error'what()实例后调用终止终止:basic_string :: _ M_construct null无效异常终止(转储核心)

but if I remove the $ from the salt it runs fine. 但是如果我从盐中除去$,它就可以正常运行。

The error message tells you that crypt returns a nullpointer for the given arguments. 错误消息告诉您crypt返回给定参数的空指针。 Most likely that's its way to signal failure. 这很可能是其发出故障信号的方式。 You need to check for that. 您需要检查一下。

You can find out more about crypt by (1) finding documentation of the function, and (2) reading it. 您可以通过(1)查找该函数的文档,以及(2)读取该函数来查找有关crypt的更多信息。

For example, you can google “unistd crypt”. 例如,您可以使用Google“ unistd crypt”。

And it so happens that the documentation specifies the valid set of characters you can use, in a nice table. 碰巧的是,文档在一个漂亮的表中指定了可以使用的有效字符集。

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

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