Skip to content

Commit

Permalink
Fix Coverity defect
Browse files Browse the repository at this point in the history
CID 456641:    (PRINTF_ARGS)
Argument "saml_port" to format specifier "%d" was expected to have
type "int" but has type "long".
  • Loading branch information
DimitriPapadopoulos committed Feb 10, 2025
1 parent 8a75d6e commit b2bedaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct vpn_config {
int password_set;
char otp[OTP_SIZE + 1];
char *cookie;
int saml_port;
uint16_t saml_port;
char saml_session_id[MAX_SAML_SESSION_ID_LENGTH + 1];
char *otp_prompt;
unsigned int otp_delay;
Expand Down
20 changes: 10 additions & 10 deletions src/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static int process_request(int new_socket, char *id)
int flag = 1;

if (setsockopt(new_socket, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag))) {
log_error("Failed to set socket options\n");
log_error("Failed to set socket options: %s\n", strerror(errno));
return -1;
}

Expand All @@ -155,7 +155,7 @@ static int process_request(int new_socket, char *id)
// If the received request from the server is larger than the buffer,
// the result will not be null-terminated causing strlen to behave wrong.
if (read_result < 0) {
log_error("Bad request\n");
log_error("Bad request: %s\n", strerror(errno));
send_status_response(new_socket, "Invalid redirect response from Fortinet server. VPN could not be established.");
return -1;
}
Expand Down Expand Up @@ -230,44 +230,43 @@ int wait_for_http_request(struct vpn_config *config)
struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
long saml_port = config->saml_port;

// Creating socket file descriptor
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd < 0) {
log_error("Failed to create socket\n");
log_error("Failed to create socket: %s\n", strerror(errno));
return -1;
}

// Forcefully attaching socket to the port
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
close(server_fd);
log_error("Failed to set socket options\n");
log_error("Failed to set socket options: %s\n", strerror(errno));
return -1;
}

address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
address.sin_port = htons(saml_port);
address.sin_port = htons(config->saml_port);

// Forcefully attaching socket to the port
if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) {
close(server_fd);
log_error("Failed to bind socket to port %d\n", saml_port);
log_error("Failed to bind socket to port %u\n", config->saml_port);
return -1;
}

if (listen(server_fd, 3) < 0) {
close(server_fd);
log_error("Failed to listen on socket\n");
log_error("Failed to listen on socket: %s\n", strerror(errno));
return -1;
}

int max_tries = 5;
fd_set readfds;
struct timeval tv;

log_info("Listening for SAML login on port %d\n", saml_port);
log_info("Listening for SAML login on port %u\n", config->saml_port);
print_url(config);

while (max_tries > 0) {
Expand All @@ -289,7 +288,8 @@ int wait_for_http_request(struct vpn_config *config)
(struct sockaddr *)&address,
(socklen_t *)&addrlen);
if (new_socket < 0) {
log_error("Failed to accept connection\n");
log_error("Failed to accept connection: %s\n",
strerror(errno));
continue;
}
} else {
Expand Down

0 comments on commit b2bedaf

Please sign in to comment.