Browse Source

[core] quiet compiler warnings

cast away signedness warning in request_check_hostname()
mod_gnutls https_add_ssl_client_entries crts allocated if crt_size != 0
  (which is already checked earlier in routine)

report from FaceBook Infer static analysis tool (https://fbinfer.com/)
- quiet dead store warnings
- check return != NULL from allocation funcs
master
Glenn Strauss 3 months ago
parent
commit
9a2404cec6
  1. 4
      src/fdevent.c
  2. 4
      src/gw_backend.c
  3. 3
      src/mod_cgi.c
  4. 2
      src/mod_cml_lua.c
  5. 2
      src/mod_deflate.c
  6. 2
      src/mod_expire.c
  7. 2
      src/mod_extforward.c
  8. 4
      src/mod_gnutls.c
  9. 1
      src/mod_magnet_cache.c
  10. 2
      src/mod_uploadprogress.c
  11. 1
      src/mod_vhostdb.c
  12. 2
      src/request.c
  13. 2
      src/stat_cache.c

4
src/fdevent.c

@ -1122,7 +1122,7 @@ __attribute_cold__ /*(convenience routine for use at config at startup)*/
char *
fdevent_load_file (const char * const fn, off_t *lim, log_error_st *errh, void *(malloc_fn)(size_t), void(free_fn)(void *))
{
int fd = -1;
int fd;
off_t sz = 0;
char *buf = NULL;
do {
@ -1175,7 +1175,7 @@ fdevent_load_file (const char * const fn, off_t *lim, log_error_st *errh, void *
int
fdevent_load_file_bytes (char * const buf, const off_t sz, off_t off, const char * const fn, log_error_st *errh)
{
int fd = -1;
int fd;
do {
fd = fdevent_open_cloexec(fn, 1, O_RDONLY, 0); /*(1: follows symlinks)*/
if (fd < 0) break;

4
src/gw_backend.c

@ -498,7 +498,6 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e
/* server is not up, spawn it */
char_array env;
uint32_t i;
int dfd = -1;
/* reopen socket */
gw_fd = fdevent_socket_cloexec(proc->saddr->sa_family, SOCK_STREAM, 0);
@ -580,7 +579,7 @@ static int gw_spawn_connection(gw_host * const host, gw_proc * const proc, log_e
env.ptr[env.used] = NULL;
}
dfd = fdevent_open_dirname(host->args.ptr[0], 1); /* permit symlinks */
int dfd = fdevent_open_dirname(host->args.ptr[0], 1);/*permit symlinks*/
if (-1 == dfd) {
log_perror(errh, __FILE__, __LINE__,
"open dirname failed: %s", host->args.ptr[0]);
@ -768,6 +767,7 @@ static int parse_binpath(char_array *env, const buffer *b) {
if (env->size == env->used) {
env->size += 16;
env->ptr = realloc(env->ptr, env->size * sizeof(*env->ptr));
force_assert(env->ptr);
}
c = b->ptr[i];

3
src/mod_cgi.c

@ -616,7 +616,6 @@ static int cgi_create_env(request_st * const r, plugin_data * const p, handler_c
char *args[3];
int to_cgi_fds[2];
int from_cgi_fds[2];
int dfd = -1;
UNUSED(p);
if (!buffer_is_blank(cgi_handler)) {
@ -683,7 +682,7 @@ static int cgi_create_env(request_st * const r, plugin_data * const p, handler_c
args[i ] = NULL;
}
dfd = fdevent_open_dirname(r->physical.path.ptr, r->conf.follow_symlink);
int dfd = fdevent_open_dirname(r->physical.path.ptr,r->conf.follow_symlink);
if (-1 == dfd) {
log_perror(r->conf.errh, __FILE__, __LINE__, "open dirname %s failed", r->physical.path.ptr);
}

2
src/mod_cml_lua.c

@ -102,7 +102,7 @@ static int cache_export_get_params(lua_State *L, int tbl, buffer *qrystr) {
int cache_parse_lua(request_st * const r, plugin_data * const p, const buffer * const fn) {
lua_State *L;
int ret = -1;
int ret;
buffer *b;
b = buffer_init();

2
src/mod_deflate.c

@ -624,6 +624,7 @@ static encparms * mod_deflate_parse_params(const array * const a, log_error_st *
static uint16_t * mod_deflate_encodings_to_flags(const array *encodings) {
if (encodings->used) {
uint16_t * const x = calloc(encodings->used+1, sizeof(short));
force_assert(x);
int i = 0;
for (uint32_t j = 0; j < encodings->used; ++j) {
#if defined(USE_ZLIB) || defined(USE_BZ2LIB) || defined(USE_BROTLI) \
@ -661,6 +662,7 @@ static uint16_t * mod_deflate_encodings_to_flags(const array *encodings) {
else {
/* default encodings */
uint16_t * const x = calloc(4+1, sizeof(short));
force_assert(x);
int i = 0;
#ifdef USE_ZSTD
x[i++] = HTTP_ACCEPT_ENCODING_ZSTD;

2
src/mod_expire.c

@ -42,7 +42,7 @@ FREE_FUNC(mod_expire_free) {
static time_t mod_expire_get_offset(log_error_st *errh, const buffer *expire, time_t *offset) {
char *ts;
time_t type = -1;
time_t type;
time_t retts = 0;
/*

2
src/mod_extforward.c

@ -889,7 +889,7 @@ static handler_t mod_extforward_Forwarded (request_st * const r, plugin_data * c
break;
}
}
i = ++j;
i = j+1;
if (-1 != oproto) {
/* remove trailing spaces/tabs, and double-quotes from proto

4
src/mod_gnutls.c

@ -2817,7 +2817,7 @@ https_add_ssl_client_entries (request_st * const r, handler_ctx * const hctx)
{
gnutls_session_t ssl = hctx->ssl;
unsigned int crt_size = 0;
const gnutls_datum_t *crts;
const gnutls_datum_t *crts = NULL;
buffer *vb = http_header_env_set_ptr(r, CONST_STR_LEN("SSL_CLIENT_VERIFY"));
if (hctx->verify_status != ~0u)
@ -2839,7 +2839,7 @@ https_add_ssl_client_entries (request_st * const r, handler_ctx * const hctx)
gnutls_x509_crt_t crt;
if (gnutls_x509_crt_init(&crt) < 0)
return;
if (gnutls_x509_crt_import(crt, &crts[0], GNUTLS_X509_FMT_DER) < 0) {
if (crts && gnutls_x509_crt_import(crt, &crts[0], GNUTLS_X509_FMT_DER) < 0){
gnutls_x509_crt_deinit(crt);
return;
}

1
src/mod_magnet_cache.c

@ -101,6 +101,7 @@ static script *script_cache_new_script(script_cache * const cache, const buffer
if (cache->used == cache->size) {
cache->size += 16;
cache->ptr = realloc(cache->ptr, cache->size * sizeof(*(cache->ptr)));
force_assert(cache->ptr);
}
cache->ptr[cache->used++] = sc;

2
src/mod_uploadprogress.c

@ -65,6 +65,7 @@ static int request_map_insert(request_map *rm, request_st * const r, const char
rm->size = rm->size ? (rm->size << 1) : 16;
force_assert(rm->size);
rm->ptr = realloc(rm->ptr, rm->size * sizeof(*(rm->ptr)));
force_assert(rm->ptr);
memset(rm->ptr+rm->used, 0, (rm->size - rm->used)*sizeof(*(rm->ptr)));
}
@ -73,6 +74,7 @@ static int request_map_insert(request_map *rm, request_st * const r, const char
rme = rm->ptr[rm->used];
} else {
rme = malloc(sizeof(*rme));
force_assert(rme);
rme->r_id = buffer_init();
}
buffer_copy_string_len(rme->r_id, r_id, idlen);

1
src/mod_vhostdb.c

@ -54,6 +54,7 @@ vhostdb_cache_entry_init (const buffer * const server_name, const buffer * const
const uint32_t dlen = buffer_clen(docroot);
vhostdb_cache_entry * const ve =
malloc(sizeof(vhostdb_cache_entry) + slen + dlen);
force_assert(ve);
ve->ctime = log_monotonic_secs;
ve->slen = slen;
ve->dlen = dlen;

2
src/request.c

@ -36,7 +36,7 @@ static int request_check_hostname(buffer * const host) {
if (*h != '[') {
uint32_t len = buffer_clen(host);
const char * const colon = memchr(h, ':', len);
uint32_t hlen = colon ? (colon - h) : len;
uint32_t hlen = colon ? (uint32_t)(colon - h) : len;
/* if hostname ends in ".", strip it */
if (__builtin_expect( (0 == hlen), 0)) return -1;

2
src/stat_cache.c

@ -1334,7 +1334,7 @@ stat_cache_entry * stat_cache_get_entry(const buffer * const name) {
stat_cache_entry_free(sptree->data);
sptree->data = sce;
} else {
sptree = sc.files = splaytree_insert(sptree, file_ndx, sce);
/*sptree =*/ sc.files = splaytree_insert(sptree, file_ndx, sce);
}
} else {

Loading…
Cancel
Save