Skip to content

Commit

Permalink
Deepcode and other fixes (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterTea authored May 3, 2021
1 parent 1d198cc commit 4459c6b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ deps
out
.vscode
*PVS-Studio*
.dccache

# Public/private keys
id_rsa*
Expand Down
2 changes: 1 addition & 1 deletion src/base/CryptoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ string CryptoHandler::encrypt(const string& buffer) {
string retval(buffer.length() + crypto_secretbox_MACBYTES, '\0');
SODIUM_FAIL(crypto_secretbox_easy((unsigned char*)&retval[0],
(const unsigned char*)buffer.c_str(),
buffer.length(), nonce, key) == -1);
buffer.length(), nonce, key));
return retval;
}

Expand Down
4 changes: 2 additions & 2 deletions src/base/Headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ inline std::vector<std::string> split(const std::string& s, char delim) {

inline bool replace(std::string& str, const std::string& from,
const std::string& to) {
size_t start_pos = str.find(from);
auto start_pos = str.find(from);
if (start_pos == std::string::npos) return false;
str.replace(start_pos, from.length(), to);
return true;
Expand All @@ -228,7 +228,7 @@ inline int replaceAll(std::string& str, const std::string& from,
const std::string& to) {
if (from.empty()) return 0;
int retval = 0;
size_t start_pos = 0;
auto start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
retval++;
str.replace(start_pos, from.length(), to);
Expand Down
7 changes: 5 additions & 2 deletions src/htm/TerminalHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "TerminalHandler.hpp"

#include "ETerminal.pb.h"
#include "RawSocketUtils.hpp"
#include "ServerConnection.hpp"
#include "UserTerminalRouter.hpp"

#include "ETerminal.pb.h"

namespace et {
TerminalHandler::TerminalHandler() : run(true), bufferLength(0) {}

Expand All @@ -16,6 +15,10 @@ void TerminalHandler::start() {
FATAL_FAIL(pid);
case 0: {
passwd* pwd = getpwuid(getuid());
if (pwd == NULL) {
LOG(FATAL)
<< "Not able to fork a terminal because getpwuid returns null";
}
chdir(pwd->pw_dir);
string terminal = string(::getenv("SHELL"));
setenv("HTM_VERSION", ET_VERSION, 1);
Expand Down
72 changes: 36 additions & 36 deletions src/terminal/ParseConfigFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ int match_hostname(const char *host, const char *pattern, unsigned int len) {
char *ssh_path_expand_tilde(const char *d) {
char *h = NULL, *r;
const char *p;
size_t ld;
size_t lh = 0;
int ld;
int lh = 0;

if (d[0] != '~') {
return strdup(d);
Expand All @@ -424,7 +424,7 @@ char *ssh_path_expand_tilde(const char *d) {
STFATAL << "~user/path format not supported on windows";
#else
struct passwd *pw;
size_t s = p - d;
int s = p - d;
char u[128];

if (s >= sizeof(u)) {
Expand Down Expand Up @@ -469,7 +469,7 @@ char *ssh_path_expand_escape(struct Options *options, const char *s) {
char buf[MAX_BUF_SIZE];
char *r, *x = NULL;
const char *p;
size_t i, l;
int i, l;

r = ssh_path_expand_tilde(s);
if (r == NULL) {
Expand Down Expand Up @@ -1081,41 +1081,41 @@ static char *ssh_config_get_token(char **str) {

/* Ignore leading spaces */
for (c = *str; *c; c++) {
if (! isblank(*c)) {
break;
}
if (!isblank(*c)) {
break;
}
}

/* If we start with quote, return the whole quoted block */
if (*c == '\"') {
for (r = ++c; *c; c++) {
if (*c == '\"' || *c == '\n') {
*c = '\0';
c++;
break;
}
/* XXX Unmatched quotes extend to the end of line */
for (r = ++c; *c; c++) {
if (*c == '\"' || *c == '\n') {
*c = '\0';
c++;
break;
}
/* XXX Unmatched quotes extend to the end of line */
}
} else {
/* Otherwise terminate on space, equal or newline */
for (r = c; *c; c++) {
if (*c == '\0') {
goto out;
} else if (isblank(*c) || *c == '=' || *c == '\n') {
had_equal = (*c == '=');
*c = '\0';
c++;
break;
}
/* Otherwise terminate on space, equal or newline */
for (r = c; *c; c++) {
if (*c == '\0') {
goto out;
} else if (isblank(*c) || *c == '=' || *c == '\n') {
had_equal = (*c == '=');
*c = '\0';
c++;
break;
}
}
}

/* Skip any other remaining whitespace */
while (isblank(*c) || *c == '\n' || (!had_equal && *c == '=')) {
if (*c == '=') {
had_equal = true;
}
c++;
if (*c == '=') {
had_equal = true;
}
c++;
}
out:
*str = c;
Expand Down Expand Up @@ -1158,7 +1158,7 @@ static int ssh_config_get_yesno(char **str, int notfound) {
}

#ifdef WIN32
#define strncasecmp(x,y,z) _strnicmp(x,y,z)
#define strncasecmp(x, y, z) _strnicmp(x, y, z)
#endif
if (strncasecmp(p, "yes", 3) == 0) {
return 1;
Expand All @@ -1172,7 +1172,7 @@ static int ssh_config_get_yesno(char **str, int notfound) {
static void local_parse_file(const char *targethost, struct Options *options,
const char *filename, int *parsing, int seen[]) {
string line;
size_t len = 0;
int len = 0;

unsigned int count = 0;

Expand All @@ -1184,8 +1184,8 @@ static void local_parse_file(const char *targethost, struct Options *options,

while (std::getline(infile, line)) {
count++;
if (ssh_config_parse_line(targethost, options, line.c_str(), count, parsing, seen) <
0) {
if (ssh_config_parse_line(targethost, options, line.c_str(), count, parsing,
seen) < 0) {
infile.close();
return;
}
Expand Down Expand Up @@ -1413,8 +1413,8 @@ static int ssh_config_parse_line(const char *targethost,
int parse_ssh_config_file(const char *targethost, struct Options *options,
string filename) {
string line;
size_t len = 0;
ssize_t read = 0;
int len = 0;
int read = 0;
unsigned int count = 0;
int parsing;
int seen[SOC_END - SOC_UNSUPPORTED] = {0};
Expand All @@ -1429,8 +1429,8 @@ int parse_ssh_config_file(const char *targethost, struct Options *options,

while (std::getline(infile, line)) {
count++;
if (ssh_config_parse_line(targethost, options, line.c_str(), count, &parsing,
seen) < 0) {
if (ssh_config_parse_line(targethost, options, line.c_str(), count,
&parsing, seen) < 0) {
infile.close();
return -1;
}
Expand Down

0 comments on commit 4459c6b

Please sign in to comment.