Browse Source

[multiple] quiet coverity warnings

includes rejigger of some code in buffer.c for Coverity to have better
visibility into what is happening in internal, private funcs
master
Glenn Strauss 8 months ago
parent
commit
f13752f3da
  1. 21
      src/buffer.c
  2. 13
      src/mod_dirlisting.c
  3. 2
      src/mod_mbedtls.c
  4. 13
      src/mod_trigger_b4_dl.c

21
src/buffer.c

@ -290,8 +290,8 @@ void buffer_append_uint_hex_lc(buffer *b, uintmax_t value) {
__attribute_nonnull__
__attribute_returns_nonnull__
static char* utostr(char * const buf_end, uintmax_t val) {
char *cur = buf_end;
static char* utostr(char buf[LI_ITOSTRING_LENGTH], uintmax_t val) {
char *cur = buf+LI_ITOSTRING_LENGTH;
do {
int mod = val % 10;
val /= 10;
@ -303,13 +303,13 @@ static char* utostr(char * const buf_end, uintmax_t val) {
__attribute_nonnull__
__attribute_returns_nonnull__
static char* itostr(char * const buf_end, intmax_t val) {
static char* itostr(char buf[LI_ITOSTRING_LENGTH], intmax_t val) {
/* absolute value not defined for INTMAX_MIN, but can take absolute
* value of any negative number via twos complement cast to unsigned.
* negative sign is prepended after (now unsigned) value is converted
* to string */
uintmax_t uval = val >= 0 ? (uintmax_t)val : ((uintmax_t)~val) + 1;
char *cur = utostr(buf_end, uval);
char *cur = utostr(buf, uval);
if (val < 0) *(--cur) = '-';
return cur;
@ -317,13 +317,8 @@ static char* itostr(char * const buf_end, intmax_t val) {
void buffer_append_int(buffer *b, intmax_t val) {
char buf[LI_ITOSTRING_LENGTH];
char* const buf_end = buf + sizeof(buf);
char *str;
str = itostr(buf_end, val);
force_assert(buf_end > str && str >= buf);
buffer_append_string_len(b, str, buf_end - str);
const char * const str = itostr(buf, val);
buffer_append_string_len(b, str, buf+sizeof(buf) - str);
}
void buffer_append_strftime(buffer * const restrict b, const char * const restrict format, const struct tm * const restrict tm) {
@ -351,7 +346,7 @@ void buffer_append_strftime(buffer * const restrict b, const char * const restri
size_t li_itostrn(char *buf, size_t buf_len, intmax_t val) {
char p_buf[LI_ITOSTRING_LENGTH];
char* const str = itostr(p_buf+sizeof(p_buf), val);
char* const str = itostr(p_buf, val);
size_t len = (size_t)(p_buf+sizeof(p_buf)-str);
force_assert(len <= buf_len);
memcpy(buf, str, len);
@ -360,7 +355,7 @@ size_t li_itostrn(char *buf, size_t buf_len, intmax_t val) {
size_t li_utostrn(char *buf, size_t buf_len, uintmax_t val) {
char p_buf[LI_ITOSTRING_LENGTH];
char* const str = utostr(p_buf+sizeof(p_buf), val);
char* const str = utostr(p_buf, val);
size_t len = (size_t)(p_buf+sizeof(p_buf)-str);
force_assert(len <= buf_len);
memcpy(buf, str, len);

13
src/mod_dirlisting.c

@ -224,12 +224,25 @@ static pcre_keyvalue_buffer * mod_dirlisting_parse_excludes(server *srv, const a
return kvb;
}
#ifdef __COVERITY__
#include "burl.h"
#endif
static int mod_dirlisting_exclude(pcre_keyvalue_buffer * const kvb, const char * const name, const uint32_t len) {
/*(re-use keyvalue.[ch] for match-only;
* must have been configured with empty kvb 'value' during init)*/
buffer input = { NULL, len+1, 0 };
*(const char **)&input.ptr = name;
pcre_keyvalue_ctx ctx = { NULL, NULL, 0, -1 };
#ifdef __COVERITY__
/*(again, must have been configured w/ empty kvb 'value' during init)*/
struct cond_match_t cache;
memset(&cache, 0, sizeof(cache));
struct burl_parts_t bp;
memset(&bp, 0, sizeof(bp));
ctx.cache = &cache;
ctx.burl = &bp;
#endif
/*(fail closed (simulate match to exclude) if there is an error)*/
return HANDLER_ERROR == pcre_keyvalue_buffer_process(kvb,&ctx,&input,NULL)
|| -1 != ctx.m;

2
src/mod_mbedtls.c

@ -2476,7 +2476,7 @@ https_add_ssl_client_entries (request_st * const r, handler_ctx * const hctx)
#if defined(MBEDTLS_PEM_WRITE_C)
/* if (NULL != crt) (e.g. not PSK-based ciphersuite) */
if (hctx->conf.ssl_verifyclient_export_cert && NULL != crt)
if (hctx->conf.ssl_verifyclient_export_cert)
https_add_ssl_client_cert(r, crt);
#endif
}

13
src/mod_trigger_b4_dl.c

@ -182,10 +182,23 @@ static int mod_trigger_b4_dl_init_regex(server * const srv, config_plugin_value_
return 1;
}
#ifdef __COVERITY__
#include "burl.h"
#endif
static int mod_trigger_b4_dl_match(pcre_keyvalue_buffer * const kvb, const buffer * const input) {
/*(re-use keyvalue.[ch] for match-only;
* must have been configured with empty kvb 'value' during init)*/
pcre_keyvalue_ctx ctx = { NULL, NULL, 0, -1 };
#ifdef __COVERITY__
/*(again, must have been configured w/ empty kvb 'value' during init)*/
struct cond_match_t cache;
memset(&cache, 0, sizeof(cache));
struct burl_parts_t bp;
memset(&bp, 0, sizeof(bp));
ctx.cache = &cache;
ctx.burl = &bp;
#endif
return HANDLER_GO_ON == pcre_keyvalue_buffer_process(kvb, &ctx, input, NULL)
&& -1 != ctx.m;
}

Loading…
Cancel
Save