Browse Source

fix some warnings reported by cppcheck

fix some warnings reported by cppcheck and
change mod_skeleton.c to use buffer_string_length()
personal/stbuehler/mod-csrf-old
Glenn Strauss 5 years ago
parent
commit
acad2c903a
  1. 4
      src/array.c
  2. 2
      src/buffer.c
  3. 2
      src/connections-glue.c
  4. 2
      src/mod_cgi.c
  5. 4
      src/mod_dirlisting.c
  6. 2
      src/mod_rewrite.c
  7. 13
      src/mod_skeleton.c

4
src/array.c

@ -353,7 +353,7 @@ int array_print(array *a, int depth) {
int j;
if (i && (i % 5) == 0) {
fprintf(stdout, "# %zd\n", i);
fprintf(stdout, "# %zu\n", i);
array_print_indent(depth + 1);
}
fprintf(stdout, "\"%s\"", du->key->ptr);
@ -367,7 +367,7 @@ int array_print(array *a, int depth) {
}
if (!(i && (i - 1 % 5) == 0)) {
array_print_indent(depth + 1);
fprintf(stdout, "# %zd\n", i);
fprintf(stdout, "# %zu\n", i);
}
array_print_indent(depth);
fprintf(stdout, ")");

2
src/buffer.c

@ -1094,7 +1094,7 @@ void print_backtrace(FILE *file) {
void log_failed_assert(const char *filename, unsigned int line, const char *msg) {
/* can't use buffer here; could lead to recursive assertions */
fprintf(stderr, "%s.%d: %s\n", filename, line, msg);
fprintf(stderr, "%s.%u: %s\n", filename, line, msg);
print_backtrace(stderr);
fflush(stderr);
abort();

2
src/connections-glue.c

@ -242,7 +242,7 @@ int connection_handle_read(server *srv, connection *con) {
len = recv(con->fd, mem, mem_len, 0);
#else /* __WIN32 */
if (ioctl(con->fd, FIONREAD, &toread) || toread == 0 || toread <= 4*1024) {
if (ioctl(con->fd, FIONREAD, &toread) || toread <= 4*1024) {
toread = 4096;
}
else if (toread > MAX_READ_LIMIT) {

2
src/mod_cgi.c

@ -387,7 +387,7 @@ static int cgi_demux_response(server *srv, handler_ctx *hctx) {
#if defined(__WIN32)
buffer_string_prepare_copy(hctx->response, 4 * 1024);
#else
if (ioctl(con->fd, FIONREAD, &toread) || toread == 0 || toread <= 4*1024) {
if (ioctl(con->fd, FIONREAD, &toread) || toread <= 4*1024) {
buffer_string_prepare_copy(hctx->response, 4 * 1024);
} else {
if (toread > MAX_READ_LIMIT) toread = MAX_READ_LIMIT;

4
src/mod_dirlisting.c

@ -437,8 +437,8 @@ static void http_dirls_sort(dirls_entry_t **ent, int num) {
* conversion is simple but not perfect
*/
static int http_list_directory_sizefmt(char *buf, size_t bufsz, off_t size) {
const char unit[] = "KMGTPE"; /* Kilo, Mega, Tera, Peta, Exa */
const char *u = unit - 1; /* u will always increment at least once */
const char unit[] = " KMGTPE"; /* Kilo, Mega, Tera, Peta, Exa */
const char *u = unit; /* u will always increment at least once */
int remain;
size_t buflen;

2
src/mod_rewrite.c

@ -495,8 +495,6 @@ URIHANDLER_FUNC(mod_rewrite_uri_handler) {
if (!p->conf.rewrite) return HANDLER_GO_ON;
return process_rewrite_rules(srv, con, p, p->conf.rewrite);
return HANDLER_GO_ON;
}
#endif

13
src/mod_skeleton.c

@ -163,25 +163,24 @@ static int mod_skeleton_patch_connection(server *srv, connection *con, plugin_da
URIHANDLER_FUNC(mod_skeleton_uri_handler) {
plugin_data *p = p_d;
int s_len;
size_t k, i;
size_t s_len;
size_t k;
UNUSED(srv);
if (con->mode != DIRECT) return HANDLER_GO_ON;
if (con->uri.path->used == 0) return HANDLER_GO_ON;
s_len = buffer_string_length(con->uri.path);
if (0 == s_len) return HANDLER_GO_ON;
mod_skeleton_patch_connection(srv, con, p);
s_len = con->uri.path->used - 1;
for (k = 0; k < p->conf.match->used; k++) {
data_string *ds = (data_string *)p->conf.match->data[k];
int ct_len = ds->value->used - 1;
size_t ct_len = buffer_string_length(ds->value);
if (ct_len > s_len) continue;
if (ds->value->used == 0) continue;
if (ct_len == 0) continue;
if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) {
con->http_status = 403;

Loading…
Cancel
Save