简体   繁体   English

使用libssl / libcrypto进行Segfault

[英]Segfault with libssl/libcrypto

This is more of a hypothetical whilst I'm debugging some code. 在调试一些代码时,这更像是一个假设。 Lets say I have an application (called X) that calls out to a lib to send an email over a TLS encrypted SMTP connection, whilst at the same time X is talking to another lib which is establishing another TLS socket through the same libcrypto lib, what's the likelyhood of getting some specific (and weird) condition where one function call would fail with a segfault? 假设我有一个应用程序(称为X)调用lib来通过TLS加密的SMTP连接发送电子邮件,同时X正在与另一个通过同一个libcrypto lib建立另一个TLS套接字的lib进行通信,获得一些特定(和奇怪)条件的可能性是什么,其中一个函数调用会因segfault而失败?

I'm kind of grasping at straws, this code worked fine up until we added the Skype SDK which connects over TLS to the Skype servers, since then we can actually get the issue to be repeatable but I'm a bit baffled as to why. 我有点抓住稻草,这段代码工作正常,直到我们添加了通过TLS连接到Skype服务器的Skype SDK,从那时起我们实际上可以让问题重复,但我有点困惑为什么。 (I'm probably overlooking the obvious, but I'll start with the really weird possibility) (我可能会忽略显而易见的事情,但我会从非常奇怪的可能性开始)

Quite genrally speaking it could be possible - but well written library should be robust to multiple access. 从一般来说,这可能是可能的 - 但是编写良好的库应该对多重访问具有强大的功能。 You might want to look through documentation to see if their API is reentrant (or even thred-safe). 您可能希望查看文档以查看其API是否可重入(甚至是安全的)。

If it is thread-safe, then (assuming that libcrypto authors didn't make mistake) you can be sure that it's not the reason of the problem. 如果它是线程安全的,那么(假设libcrypto作者没有犯错)你可以确定它不是问题的原因。

If it is reentrant, then anything using this lib in two (or more) threads should be synchronized on access (eg. using mutexes), but if parts of code are not written by you and you have no option to modiffy it, then you are stuck. 如果它是可重入的,那么在两个(或多个)线程中使用此lib的任何东西都应该在访问时同步(例如,使用互斥),但如果部分代码不是由您编写的,并且您无法修改它,那么您卡住了。 The only thing i can think of would be to use another version of libcrypto, so system creates another, unrelated instance of it's internal structure. 我唯一能想到的就是使用另一个版本的libcrypto,因此系统会创建另一个不相关的内部结构实例。 This is ugly soultion and might behave weird on user machines. 这是丑陋的灵魂,可能在用户机器上表现得很奇怪。

There's a whole man page dedicated to the usage of the OpenSSL library and threads: man 3 threads . 有一个专门用于OpenSSL库和线程的整个手册页: man 3 threads You will need to use this if your application has multiple threads that use the OpenSSL library. 如果您的应用程序有多个使用OpenSSL库的线程,则需要使用此方法。

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

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