Skip to content

Commit

Permalink
Fix crashes when some external APIs fail (#875)
Browse files Browse the repository at this point in the history
Fix crashes when some external APIs fail
  • Loading branch information
ZhouyangJia authored and koeppea committed Mar 6, 2018
1 parent 3452f2e commit e5241d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions plug-ins/sslstrip/sslstrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,19 @@ static int http_get_peer(struct http_connection *connection)
socklen_t ss_len = sizeof(struct sockaddr_storage);
switch (ntohs(connection->ip[HTTP_CLIENT].addr_type)) {
case AF_INET:
getsockopt (connection->fd, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len);
if (getsockopt (connection->fd, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len) == -1) {
WARN_MSG("getsockopt failed: %s", strerror(errno));
return -E_INVALID;
}
sa4 = (struct sockaddr_in *)&ss;
ip_addr_init(&(connection->ip[HTTP_SERVER]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr));
break;
#if defined WITH_IPV6 && defined HAVE_IP6T_SO_ORIGINAL_DST
case AF_INET6:
getsockopt (connection->fd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len);
if (getsockopt (connection->fd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len) == -1) {
WARN_MSG("getsockopt failed: %s", strerror(errno));
return -E_INVALID;
}
sa6 = (struct sockaddr_in6 *)&ss;
ip_addr_init(&(connection->ip[HTTP_SERVER]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr));
break;
Expand Down
10 changes: 8 additions & 2 deletions src/ec_sslwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,19 @@ static int sslw_get_peer(struct accepted_entry *ae)

switch (ntohs(ae->ip[SSL_CLIENT].addr_type)) {
case AF_INET:
getsockopt(ae->fd[SSL_CLIENT], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len);
if (getsockopt(ae->fd[SSL_CLIENT], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len) == -1) {
WARN_MSG("getsockopt failed: %s", strerror(errno));
return -E_INVALID;
}
sa4 = (struct sockaddr_in *)&ss;
ip_addr_init(&(ae->ip[SSL_SERVER]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr));
break;
#if defined WITH_IPV6 && defined HAVE_IP6T_SO_ORIGINAL_DST
case AF_INET6:
getsockopt(ae->fd[SSL_CLIENT], IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len);
if (getsockopt(ae->fd[SSL_CLIENT], IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len) == -1) {
WARN_MSG("getsockopt failed: %s", strerror(errno));
return -E_INVALID;
}
sa6 = (struct sockaddr_in6 *)&ss;
ip_addr_init(&(ae->ip[SSL_SERVER]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr));
break;
Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/curses/widgets/wdg_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ static int wdg_file_destroy(struct wdg_object *wo)
delwin(ww->win);

/* restore the initial working directory */
chdir(ww->initpath);
if (chdir(ww->initpath) == -1)
WARN_MSG("chdir failed: %s", strerror(errno));

WDG_SAFE_FREE(wo->extend);

Expand Down Expand Up @@ -394,7 +395,8 @@ static int wdg_file_driver(struct wdg_object *wo, int key, struct wdg_mouse_even
stat(item_name(current_item(ww->m)), &buf);
/* if it is a directory, change to it */
if (S_ISDIR(buf.st_mode)) {
chdir(item_name(current_item(ww->m)));
if (chdir(item_name(current_item(ww->m))) == -1)
WARN_MSG("chdir failed: %s", strerror(errno));
return -WDG_E_NOTHANDLED;
} else {
/* invoke the callback and return */
Expand Down

0 comments on commit e5241d8

Please sign in to comment.