weixin_39786706 2020-11-30 11:03 采纳率: 0%
浏览 0

Segmentation fault solution

From jerem....com on November 23, 2011 22:06:59

A lot of people are reporting segmentation fault in your shellinabox project. I experienced the same issue when I downloaded and built both 2.10 and the SVN tree. I ran gdb to look at the issue, and found that it’s a null pointer deference in the he->h_name usage in libhttp/ssl.c line 934:

sslGenerateCertificate(defaultCertificate, he->h_name);

In this section of code:


  char hostname[256], buf[4096];
  check(!gethostname(hostname, sizeof(hostname)));
  struct hostent he_buf, *he;
  int h_err;
  if (gethostbyname_r(hostname, &he_buf, buf, sizeof(buf),
                      &he, &h_err)) {
    sslGenerateCertificate(defaultCertificate, hostname);
  } else {
    sslGenerateCertificate(defaultCertificate, he->h_name);
  }

Accessing *he in the case that gethostbyname_r returns null is going to cause undefined behavior, in this instance a null pointer dereference. I think the if is simply upside down, which would use he->h_name if gethostbyname_r is successful, and use hostname if not.

Original issue: http://code.google.com/p/shellinabox/issues/detail?id=152

该提问来源于开源项目:shellinabox/shellinabox

  • 写回答

7条回答 默认 最新

  • weixin_39786706 2020-11-30 11:03
    关注

    From jerem....com on November 23, 2011 13:10:29

    Correction, line 676

    评论

报告相同问题?