FS-10167: More cleanup of libks, now compiles with no warnings or errors in VS2015, also fixed a bug in ks_pool.c related to logging prefix memory bounds checks. A few warnings had to be disabled entirely due to the issues coming from openssl.
This commit is contained in:
parent
4eed255acb
commit
d2facbce1e
|
@ -97,7 +97,7 @@
|
||||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<TreatWarningAsError>false</TreatWarningAsError>
|
<TreatWarningAsError>false</TreatWarningAsError>
|
||||||
<DisableSpecificWarnings>4711;4574;4100;4127;4668;4255;4706;4710;4820;4090</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4711;4574;4100;4127;4668;4255;4706;4710;4820;4090;4702</DisableSpecificWarnings>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<TargetMachine>MachineX86</TargetMachine>
|
<TargetMachine>MachineX86</TargetMachine>
|
||||||
|
@ -132,7 +132,7 @@
|
||||||
<WarningLevel>EnableAllWarnings</WarningLevel>
|
<WarningLevel>EnableAllWarnings</WarningLevel>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<TreatWarningAsError>false</TreatWarningAsError>
|
<TreatWarningAsError>false</TreatWarningAsError>
|
||||||
<DisableSpecificWarnings>4711;4574;4100;4127;4668;4255;4706;4710;4820;4090</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4711;4574;4100;4127;4668;4255;4706;4710;4820;4090;4702</DisableSpecificWarnings>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
@ -158,8 +158,6 @@
|
||||||
<ClCompile Include="crypt\aestab.c" />
|
<ClCompile Include="crypt\aestab.c" />
|
||||||
<ClCompile Include="crypt\aes_modes.c" />
|
<ClCompile Include="crypt\aes_modes.c" />
|
||||||
<ClCompile Include="crypt\sha2.c" />
|
<ClCompile Include="crypt\sha2.c" />
|
||||||
<ClCompile Include="crypt\twofish.c" />
|
|
||||||
<ClCompile Include="crypt\twofish_cfb.c" />
|
|
||||||
<ClCompile Include="src\cJSON.c" />
|
<ClCompile Include="src\cJSON.c" />
|
||||||
<ClCompile Include="src\cJSON_Utils.c" />
|
<ClCompile Include="src\cJSON_Utils.c" />
|
||||||
<ClCompile Include="src\ks.c" />
|
<ClCompile Include="src\ks.c" />
|
||||||
|
@ -194,7 +192,6 @@
|
||||||
<ClInclude Include="crypt\brg_endian.h" />
|
<ClInclude Include="crypt\brg_endian.h" />
|
||||||
<ClInclude Include="crypt\brg_types.h" />
|
<ClInclude Include="crypt\brg_types.h" />
|
||||||
<ClInclude Include="crypt\sha2.h" />
|
<ClInclude Include="crypt\sha2.h" />
|
||||||
<ClInclude Include="crypt\twofish.h" />
|
|
||||||
<ClInclude Include="src\include\ks.h" />
|
<ClInclude Include="src\include\ks.h" />
|
||||||
<ClInclude Include="src\include\ks_acl.h" />
|
<ClInclude Include="src\include\ks_acl.h" />
|
||||||
<ClInclude Include="src\include\ks_base64.h" />
|
<ClInclude Include="src\include\ks_base64.h" />
|
||||||
|
|
|
@ -84,12 +84,6 @@
|
||||||
<ClCompile Include="crypt\sha2.c">
|
<ClCompile Include="crypt\sha2.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="crypt\twofish.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="crypt\twofish_cfb.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\ks_ssl.c">
|
<ClCompile Include="src\ks_ssl.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -167,9 +161,6 @@
|
||||||
<ClInclude Include="crypt\sha2.h">
|
<ClInclude Include="crypt\sha2.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="crypt\twofish.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\win\sys\mman.h">
|
<ClInclude Include="src\win\sys\mman.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -63,8 +63,13 @@ KS_DECLARE(ks_status_t) ks_global_set_cleanup(ks_pool_cleanup_fn_t fn, void *arg
|
||||||
|
|
||||||
KS_DECLARE(ks_status_t) ks_init(void)
|
KS_DECLARE(ks_status_t) ks_init(void)
|
||||||
{
|
{
|
||||||
|
unsigned int pid = 0;
|
||||||
srand(getpid() * (intptr_t)&pool + time(NULL));
|
#ifdef __WINDOWS__
|
||||||
|
pid = _getpid();
|
||||||
|
#else
|
||||||
|
pid = getpid();
|
||||||
|
#endif
|
||||||
|
srand(pid * (unsigned int)(intptr_t)&pool + (unsigned int)time(NULL));
|
||||||
ks_ssl_init_ssl_locks();
|
ks_ssl_init_ssl_locks();
|
||||||
ks_global_pool();
|
ks_global_pool();
|
||||||
ks_rng_init();
|
ks_rng_init();
|
||||||
|
|
|
@ -110,7 +110,7 @@ static void default_logger(const char *file, const char *func, int line, int lev
|
||||||
used += snprintf(buf + used - 1, sizeof(buf) - used, "#%d ", (int32_t)ks_thread_self_id());
|
used += snprintf(buf + used - 1, sizeof(buf) - used, "#%d ", (int32_t)ks_thread_self_id());
|
||||||
}
|
}
|
||||||
if (ks_log_prefix & KS_LOG_PREFIX_FILE) {
|
if (ks_log_prefix & KS_LOG_PREFIX_FILE) {
|
||||||
used += snprintf(buf + used - 1, sizeof(buf) - used, fp);
|
used += snprintf(buf + used - 1, sizeof(buf) - used, "%s", fp);
|
||||||
if (ks_log_prefix & KS_LOG_PREFIX_LINE) {
|
if (ks_log_prefix & KS_LOG_PREFIX_LINE) {
|
||||||
used += snprintf(buf + used - 1, sizeof(buf) - used, ":%d", line);
|
used += snprintf(buf + used - 1, sizeof(buf) - used, ":%d", line);
|
||||||
}
|
}
|
||||||
|
@ -120,10 +120,10 @@ static void default_logger(const char *file, const char *func, int line, int lev
|
||||||
used += snprintf(buf + used - 1, sizeof(buf) - used, "%s() ", func);
|
used += snprintf(buf + used - 1, sizeof(buf) - used, "%s() ", func);
|
||||||
}
|
}
|
||||||
|
|
||||||
used += snprintf(buf + used - 1, sizeof(buf) - used, data);
|
used += snprintf(buf + used - 1, sizeof(buf) - used, "%s", data);
|
||||||
|
|
||||||
//fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], fp, line, func, data);
|
//fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], fp, line, func, data);
|
||||||
fprintf(stderr, buf);
|
fprintf(stderr, "%s", buf);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -953,7 +953,6 @@ static void *alloc_mem(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
|
||||||
prefix->refs++;
|
prefix->refs++;
|
||||||
|
|
||||||
if (mp_p->mp_log_func != NULL) {
|
if (mp_p->mp_log_func != NULL) {
|
||||||
alloc_prefix_t *prefix = (alloc_prefix_t *) ((char *) addr - PREFIX_SIZE);
|
|
||||||
mp_p->mp_log_func(mp_p, KS_POOL_FUNC_INCREF, prefix->size, prefix->refs, NULL, addr, 0);
|
mp_p->mp_log_func(mp_p, KS_POOL_FUNC_INCREF, prefix->size, prefix->refs, NULL, addr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1728,7 +1727,6 @@ KS_DECLARE(void *) ks_pool_ref_ex(ks_pool_t *mp_p, void *addr, ks_status_t *erro
|
||||||
prefix->refs++;
|
prefix->refs++;
|
||||||
|
|
||||||
if (mp_p->mp_log_func != NULL) {
|
if (mp_p->mp_log_func != NULL) {
|
||||||
alloc_prefix_t *prefix = (alloc_prefix_t *) ((char *) addr - PREFIX_SIZE);
|
|
||||||
mp_p->mp_log_func(mp_p, KS_POOL_FUNC_INCREF, prefix->size, prefix->refs, NULL, addr, 0);
|
mp_p->mp_log_func(mp_p, KS_POOL_FUNC_INCREF, prefix->size, prefix->refs, NULL, addr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ static inline void ks_ssl_lock_callback(int mode, int type, char *file, int line
|
||||||
|
|
||||||
static inline unsigned long ks_ssl_thread_id(void)
|
static inline unsigned long ks_ssl_thread_id(void)
|
||||||
{
|
{
|
||||||
return (unsigned long) ks_thread_self();
|
return ks_thread_self_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
KS_DECLARE(void) ks_ssl_init_ssl_locks(void)
|
KS_DECLARE(void) ks_ssl_init_ssl_locks(void)
|
||||||
|
|
|
@ -97,6 +97,7 @@ static int cheezy_get_var(char *data, char *name, char *buf, ks_size_t buflen)
|
||||||
/* the old way didnt make sure that variable values were used for the name hunt
|
/* the old way didnt make sure that variable values were used for the name hunt
|
||||||
* and didnt ensure that only a full match of the variable name was used
|
* and didnt ensure that only a full match of the variable name was used
|
||||||
*/
|
*/
|
||||||
|
ks_assert(buflen > 0);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!strncmp(p,name,strlen(name)) && *(p+strlen(name))==':') break;
|
if(!strncmp(p,name,strlen(name)) && *(p+strlen(name))==':') break;
|
||||||
|
@ -120,11 +121,11 @@ static int cheezy_get_var(char *data, char *name, char *buf, ks_size_t buflen)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v && e) {
|
if (v && e) {
|
||||||
int cplen;
|
size_t cplen;
|
||||||
ks_size_t len = e - v;
|
ks_size_t len = e - v;
|
||||||
|
|
||||||
if (len > buflen - 1) {
|
if (len > buflen - 1) {
|
||||||
cplen = buflen -1;
|
cplen = buflen - 1;
|
||||||
} else {
|
} else {
|
||||||
cplen = len;
|
cplen = len;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +278,7 @@ static int ws_server_handshake(kws_t *kws)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < 0 || bytes > kws->buflen -1) {
|
if (bytes < 0 || ((ks_size_t)bytes) > kws->buflen - 1) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +295,7 @@ static int ws_server_handshake(kws_t *kws)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
kws->uri = ks_pool_alloc(kws->pool, (e-p) + 1);
|
kws->uri = ks_pool_alloc(kws->pool, (unsigned long)(e-p) + 1);
|
||||||
strncpy(kws->uri, p, e-p);
|
strncpy(kws->uri, p, e-p);
|
||||||
*(kws->uri + (e-p)) = '\0';
|
*(kws->uri + (e-p)) = '\0';
|
||||||
|
|
||||||
|
@ -353,7 +354,7 @@ static int ws_server_handshake(kws_t *kws)
|
||||||
|
|
||||||
KS_DECLARE(ks_ssize_t) kws_raw_read(kws_t *kws, void *data, ks_size_t bytes, int block)
|
KS_DECLARE(ks_ssize_t) kws_raw_read(kws_t *kws, void *data, ks_size_t bytes, int block)
|
||||||
{
|
{
|
||||||
ks_ssize_t r;
|
int r;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
kws->x++;
|
kws->x++;
|
||||||
|
@ -361,7 +362,7 @@ KS_DECLARE(ks_ssize_t) kws_raw_read(kws_t *kws, void *data, ks_size_t bytes, int
|
||||||
|
|
||||||
if (kws->ssl) {
|
if (kws->ssl) {
|
||||||
do {
|
do {
|
||||||
r = SSL_read(kws->ssl, data, bytes);
|
r = SSL_read(kws->ssl, data, (int)bytes);
|
||||||
|
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
err = SSL_get_error(kws->ssl, r);
|
err = SSL_get_error(kws->ssl, r);
|
||||||
|
@ -386,7 +387,7 @@ KS_DECLARE(ks_ssize_t) kws_raw_read(kws_t *kws, void *data, ks_size_t bytes, int
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
r = recv(kws->sock, data, bytes, 0);
|
r = recv(kws->sock, data, (int)bytes, 0);
|
||||||
|
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
if (!block && ks_errno_is_blocking(ks_errno())) {
|
if (!block && ks_errno_is_blocking(ks_errno())) {
|
||||||
|
@ -420,14 +421,14 @@ KS_DECLARE(ks_ssize_t) kws_raw_read(kws_t *kws, void *data, ks_size_t bytes, int
|
||||||
|
|
||||||
KS_DECLARE(ks_ssize_t) kws_raw_write(kws_t *kws, void *data, ks_size_t bytes)
|
KS_DECLARE(ks_ssize_t) kws_raw_write(kws_t *kws, void *data, ks_size_t bytes)
|
||||||
{
|
{
|
||||||
ks_ssize_t r;
|
int r;
|
||||||
int sanity = WS_WRITE_SANITY;
|
int sanity = WS_WRITE_SANITY;
|
||||||
int ssl_err = 0;
|
int ssl_err = 0;
|
||||||
ks_size_t wrote = 0;
|
ks_size_t wrote = 0;
|
||||||
|
|
||||||
if (kws->ssl) {
|
if (kws->ssl) {
|
||||||
do {
|
do {
|
||||||
r = SSL_write(kws->ssl, (void *)((unsigned char *)data + wrote), bytes - wrote);
|
r = SSL_write(kws->ssl, (void *)((unsigned char *)data + wrote), (int)(bytes - wrote));
|
||||||
|
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
wrote += r;
|
wrote += r;
|
||||||
|
@ -460,7 +461,7 @@ KS_DECLARE(ks_ssize_t) kws_raw_write(kws_t *kws, void *data, ks_size_t bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
r = send(kws->sock, (void *)((unsigned char *)data + wrote), bytes - wrote, 0);
|
r = send(kws->sock, (void *)((unsigned char *)data + wrote), (int)(bytes - wrote), 0);
|
||||||
|
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
wrote += r;
|
wrote += r;
|
||||||
|
@ -516,7 +517,7 @@ static int establish_client_logical_layer(kws_t *kws)
|
||||||
kws->ssl = SSL_new(kws->ssl_ctx);
|
kws->ssl = SSL_new(kws->ssl_ctx);
|
||||||
assert(kws->ssl);
|
assert(kws->ssl);
|
||||||
|
|
||||||
SSL_set_fd(kws->ssl, kws->sock);
|
SSL_set_fd(kws->ssl, (int)kws->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -593,7 +594,7 @@ static int establish_server_logical_layer(kws_t *kws)
|
||||||
kws->ssl = SSL_new(kws->ssl_ctx);
|
kws->ssl = SSL_new(kws->ssl_ctx);
|
||||||
assert(kws->ssl);
|
assert(kws->ssl);
|
||||||
|
|
||||||
SSL_set_fd(kws->ssl, kws->sock);
|
SSL_set_fd(kws->ssl, (int)kws->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -707,8 +708,8 @@ KS_DECLARE(ks_status_t) kws_init(kws_t **kwsP, ks_socket_t sock, SSL_CTX *ssl_ct
|
||||||
kws->buflen = 1024 * 64;
|
kws->buflen = 1024 * 64;
|
||||||
kws->bbuflen = kws->buflen;
|
kws->bbuflen = kws->buflen;
|
||||||
|
|
||||||
kws->buffer = ks_pool_alloc(kws->pool, kws->buflen);
|
kws->buffer = ks_pool_alloc(kws->pool, (unsigned long)kws->buflen);
|
||||||
kws->bbuffer = ks_pool_alloc(kws->pool, kws->bbuflen);
|
kws->bbuffer = ks_pool_alloc(kws->pool, (unsigned long)kws->bbuflen);
|
||||||
//printf("init %p %ld\n", (void *) kws->bbuffer, kws->bbuflen);
|
//printf("init %p %ld\n", (void *) kws->bbuffer, kws->bbuflen);
|
||||||
//memset(kws->buffer, 0, kws->buflen);
|
//memset(kws->buffer, 0, kws->buflen);
|
||||||
//memset(kws->bbuffer, 0, kws->bbuflen);
|
//memset(kws->bbuffer, 0, kws->bbuflen);
|
||||||
|
@ -946,7 +947,7 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
|
||||||
|
|
||||||
if (kws->plen == 127) {
|
if (kws->plen == 127) {
|
||||||
uint64_t *u64;
|
uint64_t *u64;
|
||||||
int more = 0;
|
ks_ssize_t more = 0;
|
||||||
|
|
||||||
need += 8;
|
need += 8;
|
||||||
|
|
||||||
|
@ -955,7 +956,7 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
|
||||||
//*oc = WSOC_CLOSE;
|
//*oc = WSOC_CLOSE;
|
||||||
//return kws_close(kws, WS_PROTO_ERR);
|
//return kws_close(kws, WS_PROTO_ERR);
|
||||||
|
|
||||||
more = kws_raw_read(kws, kws->buffer + kws->datalen, need - kws->datalen, WS_BLOCK);
|
more = kws_raw_read(kws, kws->buffer + kws->datalen, (int)(need - kws->datalen), WS_BLOCK);
|
||||||
|
|
||||||
if (more < 0 || more < need - kws->datalen) {
|
if (more < 0 || more < need - kws->datalen) {
|
||||||
*oc = WSOC_CLOSE;
|
*oc = WSOC_CLOSE;
|
||||||
|
@ -999,14 +1000,14 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
|
||||||
return kws_close(kws, WS_NONE);
|
return kws_close(kws, WS_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
blen = kws->body - kws->bbuffer;
|
blen = (int)(kws->body - kws->bbuffer);
|
||||||
|
|
||||||
if (need + blen > (ks_ssize_t)kws->bbuflen) {
|
if (need + blen > (ks_ssize_t)kws->bbuflen) {
|
||||||
void *tmp;
|
void *tmp;
|
||||||
|
|
||||||
kws->bbuflen = need + blen + kws->rplen;
|
kws->bbuflen = need + blen + kws->rplen;
|
||||||
|
|
||||||
if ((tmp = ks_pool_resize(kws->pool, kws->bbuffer, kws->bbuflen))) {
|
if ((tmp = ks_pool_resize(kws->pool, kws->bbuffer, (unsigned long)kws->bbuflen))) {
|
||||||
kws->bbuffer = tmp;
|
kws->bbuffer = tmp;
|
||||||
} else {
|
} else {
|
||||||
abort();
|
abort();
|
||||||
|
@ -1146,7 +1147,7 @@ KS_DECLARE(ks_ssize_t) kws_write_frame(kws_t *kws, kws_opcode_t oc, void *data,
|
||||||
void *tmp;
|
void *tmp;
|
||||||
|
|
||||||
kws->write_buffer_len = hlen + bytes + 1;
|
kws->write_buffer_len = hlen + bytes + 1;
|
||||||
if ((tmp = ks_pool_resize(kws->pool, kws->write_buffer, kws->write_buffer_len))) {
|
if ((tmp = ks_pool_resize(kws->pool, kws->write_buffer, (unsigned long)kws->write_buffer_len))) {
|
||||||
kws->write_buffer = tmp;
|
kws->write_buffer = tmp;
|
||||||
} else {
|
} else {
|
||||||
abort();
|
abort();
|
||||||
|
|
Loading…
Reference in New Issue