diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index e8f65e12..140b1861 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -1,5 +1,6 @@ Portions Copyright (C) 2010-2013 Serval Project Inc. Portions Copyright (C) 2010-2013 Paul Gardner-Stephen +Portions Copyright (C) 2013 Petter Reinholdtsen Portions Copyright (C) 2000-2001 Aaron D. Gifford Portions Copyright (C) 2010-2012 Serval Project Pty Limited Portions Copyright (C) 2006-2008 Linpro AS diff --git a/Makefile.in b/Makefile.in index d23f66c0..ee5f0e8e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -83,6 +83,12 @@ INSTALL_DATA= $(INSTALL) -m 644 -include Makefile.dbg +# More warnings, discover problems that only happen on some archs +CFLAGS+=-Wextra +# Security enhancements from Debian +CFLAGS+=-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 +LDFLAGS+=-Wl,-z,relro + DEFS= @DEFS@ .PHONY: all test clean diff --git a/cli.c b/cli.c index 87b0551d..b2914ad0 100644 --- a/cli.c +++ b/cli.c @@ -44,7 +44,7 @@ int cli_usage_args(const int argc, const char *const *args, const struct cli_sch unsigned cmd; int matched_any = 0; for (cmd = 0; commands[cmd].function; ++cmd) { - unsigned opt; + int opt; const char *word; int matched = 1; for (opt = 0; matched && opt < argc && (word = commands[cmd].words[opt]); ++opt) @@ -99,7 +99,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema * cmdpa.labelc = 0; cmdpa.varargi = -1; const char *pattern = NULL; - unsigned arg = 0; + int arg = 0; unsigned opt = 0; while ((pattern = commands[cmd].words[opt])) { //DEBUGF("cmd=%d opt=%d pattern='%s' args[arg=%d]='%s'", cmd, opt, pattern, arg, arg < argc ? args[arg] : ""); @@ -167,7 +167,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema * pattern += 1; patlen -= 2; } - unsigned oarg = arg; + int oarg = arg; const char *text = NULL; const char *label = NULL; unsigned labellen = 0; @@ -195,7 +195,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema * // Look for a match. const char *prefix = NULL; unsigned prefixlen = 0; - char prefixarglen = 0; + unsigned prefixarglen = 0; const char *caret = strchr(word, '<'); if (wordlen > 2 && caret && word[wordlen-1] == '>') { if ((prefixarglen = prefixlen = caret - word)) { @@ -277,7 +277,7 @@ void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *par { DEBUG_argv("command", parsed->argc, parsed->args); strbuf b = strbuf_alloca(1024); - int i; + unsigned i; for (i = 0; i < parsed->labelc; ++i) { const struct labelv *lab = &parsed->labelv[i]; strbuf_sprintf(b, " %s=%s", alloca_toprint(-1, lab->label, lab->len), alloca_str_toprint(lab->text)); @@ -297,10 +297,10 @@ int cli_invoke(const struct cli_parsed *parsed, struct cli_context *context) int _cli_arg(struct __sourceloc __whence, const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue) { - int labellen = strlen(label); + unsigned labellen = strlen(label); if (dst) *dst = defaultvalue; - int i; + unsigned i; for (i = 0; i < parsed->labelc; ++i) { if (parsed->labelv[i].len == labellen && strncasecmp(label, parsed->labelv[i].label, labellen) == 0) { const char *value = parsed->labelv[i].text; diff --git a/cli.h b/cli.h index 1c139278..40fa0e85 100644 --- a/cli.h +++ b/cli.h @@ -92,8 +92,7 @@ int cli_optional_did(const char *text); int cli_putchar(struct cli_context *context, char c); int cli_puts(struct cli_context *context, const char *str); -int cli_printf(struct cli_context *context, const char *fmt, ...) -__attribute__ (( format(printf,2,3) )); +void cli_printf(struct cli_context *context, const char *fmt, ...) __attribute__ (( format(printf,2,3) )); int cli_delim(struct cli_context *context, const char *opt); void cli_columns(struct cli_context *context, int columns, const char *names[]); void cli_row_count(struct cli_context *context, int rows); diff --git a/commandline.c b/commandline.c index d4960d05..ae024d19 100644 --- a/commandline.c +++ b/commandline.c @@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* + Portions Copyright (C) 2013 Petter Reinholdtsen + Some rights reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + #include #include #include @@ -50,13 +79,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. extern struct cli_schema command_line_options[]; -int commandline_usage(const struct cli_parsed *parsed, struct cli_context *context) +int commandline_usage(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { printf("Serval DNA version %s\nUsage:\n", version_servald); return cli_usage_parsed(parsed, XPRINTF_STDIO(stdout)); } -int version_message(const struct cli_parsed *parsed, struct cli_context *context) +int version_message(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context)) { printf("Serval DNA version %s\n%s\n", version_servald, copyright_servald); printf("\ @@ -79,15 +108,19 @@ jmethodID startResultSet, setColumnName, putString, putBlob, putLong, putDouble, static int outv_growbuf(struct cli_context *context, size_t needed) { - size_t newsize = (context->outv_limit - context->outv_current < needed) ? (context->outv_limit - context->outv_buffer) + needed : 0; - if (newsize) { + assert(context->outv_current <= context->outv_limit); + size_t remaining = (size_t)(context->outv_limit - context->outv_current); + if (remaining < needed) { + size_t cursize = context->outv_current - context->outv_buffer; + size_t newsize = cursize + needed; // Round up to nearest multiple of OUTV_BUFFER_ALLOCSIZE. newsize = newsize + OUTV_BUFFER_ALLOCSIZE - ((newsize - 1) % OUTV_BUFFER_ALLOCSIZE + 1); - size_t length = context->outv_current - context->outv_buffer; + assert(newsize > cursize); + assert((size_t)(newsize - cursize) >= needed); context->outv_buffer = realloc(context->outv_buffer, newsize); if (context->outv_buffer == NULL) return WHYF("Out of memory allocating %lu bytes", (unsigned long) newsize); - context->outv_current = context->outv_buffer + length; + context->outv_current = context->outv_buffer + cursize; context->outv_limit = context->outv_buffer + newsize; } return 0; @@ -136,7 +169,7 @@ int Throw(JNIEnv *env, const char *class, const char *msg) /* JNI entry point to command line. See org.servalproject.servald.ServalD class for the Java side. JNI method descriptor: "(Ljava/util/List;[Ljava/lang/String;)I" */ -JNIEXPORT jint JNICALL Java_org_servalproject_servald_ServalD_rawCommand(JNIEnv *env, jobject this, jobject outv, jobjectArray args) +JNIEXPORT jint JNICALL Java_org_servalproject_servald_ServalD_rawCommand(JNIEnv *env, jobject UNUSED(this), jobject outv, jobjectArray args) { struct cli_context context; bzero(&context, sizeof(context)); @@ -311,36 +344,45 @@ int cli_puts(struct cli_context *context, const char *str) } /* Write a formatted string to output. If in a JNI call, then this appends the string to the - current output field, excluding the terminating null. Returns the number of bytes - written/appended, or -1 on error. + current output field, excluding the terminating null. */ -int cli_printf(struct cli_context *context, const char *fmt, ...) +void cli_printf(struct cli_context *context, const char *fmt, ...) { - int ret = 0; va_list ap; #ifdef HAVE_JNI_H if (context && context->jni_env) { + assert(context->outv_current <= context->outv_limit); size_t avail = context->outv_limit - context->outv_current; va_start(ap, fmt); int count = vsnprintf(context->outv_current, avail, fmt, ap); va_end(ap); - if (count >= avail) { - if (outv_growbuf(context, count) == -1) - return -1; - va_start(ap, fmt); - vsprintf(context->outv_current, fmt, ap); - va_end(ap); + if (count < 0) { + WHYF("vsnprintf(%p,%zu,%s,...) failed", context->outv_current, avail, alloca_str_toprint(fmt)); + return; + } else if ((size_t)count < avail) { + context->outv_current += count; + return; } - context->outv_current += count; - ret = count; + if (outv_growbuf(context, count) == -1) + return; + avail = context->outv_limit - context->outv_current; + va_start(ap, fmt); + count = vsprintf(context->outv_current, fmt, ap); + va_end(ap); + if (count < 0) { + WHYF("vsprintf(%p,%s,...) failed", context->outv_current, alloca_str_toprint(fmt)); + return; + } + assert((size_t)count < avail); + context->outv_current += (size_t)count; } else #endif { va_start(ap, fmt); - ret = vfprintf(stdout, fmt, ap); + if (vfprintf(stdout, fmt, ap) < 0) + WHYF("vfprintf(stdout,%s,...) failed", alloca_str_toprint(fmt)); va_end(ap); } - return ret; } void cli_columns(struct cli_context *context, int columns, const char *names[]) @@ -490,7 +532,7 @@ int app_echo(const struct cli_parsed *parsed, struct cli_context *context) if (config.debug.verbose) DEBUG_cli_parsed(parsed); int escapes = !cli_arg(parsed, "-e", NULL, NULL, NULL); - int i; + unsigned i; for (i = parsed->varargi; i < parsed->argc; ++i) { const char *arg = parsed->args[i]; if (config.debug.verbose) @@ -506,7 +548,7 @@ int app_echo(const struct cli_parsed *parsed, struct cli_context *context) return 0; } -int app_log(const struct cli_parsed *parsed, struct cli_context *context) +int app_log(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); @@ -1009,7 +1051,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context) uint8_t recv_payload[12]; ssize_t len = mdp_recv(mdp_sockfd, &mdp_recv_header, recv_payload, sizeof(recv_payload)); - if (len<0){ + if (len == -1){ WHY_perror("mdp_recv"); break; } @@ -1027,7 +1069,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context) continue; } - if (len const char *var[parsed->argc - 1]; const char *val[parsed->argc - 1]; - int nvar = 0; - int i; + unsigned nvar = 0; + unsigned i; for (i = 1; i < parsed->argc; ++i) { const char *arg = parsed->args[i]; int iv; @@ -1597,7 +1639,7 @@ cleanup: return status; } -int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_context *context) +int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); @@ -1621,7 +1663,7 @@ int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_cont return ret; } -int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *context) +int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); @@ -1791,7 +1833,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con retfile = rhizome_extract_file(m, filepath); }else{ // Save the file without attempting to decrypt - int64_t length; + uint64_t length; retfile = rhizome_dump_file(&m->filehash, filepath, &length); } } @@ -1841,7 +1883,7 @@ int app_rhizome_export_file(const struct cli_parsed *parsed, struct cli_context return -1; if (!rhizome_exists(&hash)) return 1; - int64_t length; + uint64_t length; int ret = rhizome_dump_file(&hash, filepath, &length); if (ret) return ret == -1 ? -1 : 1; @@ -1951,7 +1993,7 @@ int app_rhizome_list(const struct cli_parsed *parsed, struct cli_context *contex return 0; } -int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *context) +int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); @@ -1962,7 +2004,7 @@ int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *cont return 0; } -int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *context) +int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); @@ -1989,7 +2031,7 @@ int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *contex return ret; } -int app_keyring_load(const struct cli_parsed *parsed, struct cli_context *context) +int app_keyring_load(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); @@ -2039,7 +2081,7 @@ int app_keyring_list(const struct cli_parsed *parsed, struct cli_context *contex keyring_file *k = keyring_open_instance_cli(parsed); if (!k) return -1; - int cn, in; + unsigned cn, in; for (cn = 0; cn < k->context_count; ++cn) for (in = 0; in < k->contexts[cn]->identity_count; ++in) { const sid_t *sidp = NULL; @@ -2058,7 +2100,7 @@ int app_keyring_list(const struct cli_parsed *parsed, struct cli_context *contex static void cli_output_identity(struct cli_context *context, const keyring_identity *id) { - int i; + unsigned i; for (i=0;ikeypair_count;i++){ keypair *kp=id->keypairs[i]; switch(kp->type){ @@ -2107,6 +2149,7 @@ int app_keyring_add(const struct cli_parsed *parsed, struct cli_context *context if (!k) return -1; keyring_enter_pin(k, pin); + assert(k->context_count > 0); const keyring_identity *id = keyring_create_identity(k, k->contexts[k->context_count - 1], pin); if (id == NULL) { keyring_free(k); @@ -2152,7 +2195,7 @@ int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *con if (!(keyring = keyring_open_instance_cli(parsed))) return -1; - int cn=0,in=0,kp=0; + unsigned cn=0, in=0, kp=0; int r=0; if (!keyring_find_sid(keyring, &cn, &in, &kp, &sid)) r=WHY("No matching SID"); @@ -2187,7 +2230,7 @@ static int app_keyring_set_tag(const struct cli_parsed *parsed, struct cli_conte if (str_to_sid_t(&sid, sidhex) == -1) return WHY("str_to_sid_t() failed"); - int cn=0,in=0,kp=0; + unsigned cn=0, in=0, kp=0; int r=0; if (!keyring_find_sid(keyring, &cn, &in, &kp, &sid)) r=WHY("No matching SID"); @@ -2226,7 +2269,7 @@ ssize_t mdp_poll_recv(int mdp_sock, time_ms_t timeout, struct mdp_header *rev_he return len; } -static int handle_pins(const struct cli_parsed *parsed, struct cli_context *context, int revoke) +static int handle_pins(const struct cli_parsed *parsed, struct cli_context *UNUSED(context), int revoke) { const char *pin, *sid_hex; if (cli_arg(parsed, "entry-pin", &pin, NULL, "") == -1 || @@ -2248,22 +2291,21 @@ static int handle_pins(const struct cli_parsed *parsed, struct cli_context *cont }else{ request->action=ACTION_UNLOCK; } - int len = sizeof(struct mdp_identity_request); - - if (pin && *pin){ + size_t len = sizeof(struct mdp_identity_request); + if (pin && *pin) { request->type=TYPE_PIN; - int pin_len = strlen(pin)+1; - if (pin_len+len > sizeof(request_payload)) + size_t pin_siz = strlen(pin) + 1; + if (pin_siz + len > sizeof(request_payload)) return WHY("Supplied pin is too long"); - bcopy(pin, &request_payload[len], pin_len); - len+=pin_len; + bcopy(pin, &request_payload[len], pin_siz); + len += pin_siz; }else if(sid_hex && *sid_hex){ request->type=TYPE_SID; sid_t sid; if (str_to_sid_t(&sid, sid_hex) == -1) return WHY("str_to_sid_t() failed"); bcopy(sid.binary, &request_payload[len], sizeof(sid)); - len+=sizeof(sid); + len += sizeof(sid); } if (!mdp_send(mdp_sock, &header, request_payload, len)){ @@ -2404,7 +2446,7 @@ int app_id_self(const struct cli_parsed *parsed, struct cli_context *context) overlay_mdp_client_close(mdp_sockfd); return WHY("MDP Server returned something other than an address list"); } - int i; + unsigned i; for(i=0;inodc) { // Binary search for matching child. @@ -132,9 +132,9 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const c = strncmp(key, child->key, keylen); if (c == 0 && child->key[keylen]) c = -1; - //DEBUGF(" m=%d n=%d i=%d child->key=%s c=%d", m, n, i, alloca_str_toprint(child->key), c); + //DEBUGF(" m=%u n=%u i=%u child->key=%s c=%d", m, n, i, alloca_str_toprint(child->key), c); if (c == 0) { - //DEBUGF(" found i=%d", i); + //DEBUGF(" found i=%u", i); return i; } if (c > 0) @@ -144,7 +144,6 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const } while (m <= n); } // At this point, i is the index where a new child should be inserted. - assert(i >= 0); assert(i <= (*parentp)->nodc); if ((child = emalloc_zero(sizeof *child)) == NULL) return -1; @@ -156,11 +155,11 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const ++(*parentp)->nodc; if ((*parentp)->nodc > NELS((*parentp)->nodv)) *parentp = realloc(*parentp, sizeof(**parentp) + sizeof((*parentp)->nodv[0]) * ((*parentp)->nodc - NELS((*parentp)->nodv))); - int j; + unsigned j; for (j = (*parentp)->nodc - 1; j > i; --j) (*parentp)->nodv[j] = (*parentp)->nodv[j-1]; (*parentp)->nodv[i] = child; - //DEBUGF(" insert i=%d", i); + //DEBUGF(" insert i=%u", i); return i; } @@ -184,7 +183,7 @@ int cf_om_get_child(const struct cf_om_node *parent, const char *key, const char if (keyend == NULL) keyend = key + strlen(key); // TODO: use binary search, since child nodes are already sorted by key - int i; + unsigned i; for (i = 0; i < parent->nodc; ++i) if (memcmp(parent->nodv[i]->key, key, keyend - key) == 0 && parent->nodv[i]->key[keyend - key] == '\0') return i; @@ -318,7 +317,7 @@ void cf_om_dump_node(const struct cf_om_node *node, int indent) alloca_str_toprint(node->key), alloca_str_toprint(node->text) ); - int i; + unsigned i; for (i = 0; i < node->nodc; ++i) cf_om_dump_node(node->nodv[i], indent + 1); } @@ -445,7 +444,7 @@ int cf_om_iter_next(struct cf_om_iterator *it) return 0; while (1) { const struct cf_om_node *parent = it->stack[it->sp].node; - int i = it->stack[it->sp].index++; + unsigned i = it->stack[it->sp].index++; if (i < parent->nodc) { it->node = parent->nodv[i]; if (it->node == NULL) @@ -487,7 +486,7 @@ void _cf_warn_nodev(struct __sourceloc __whence, const struct cf_om_node *node, void _cf_warn_childrenv(struct __sourceloc __whence, const struct cf_om_node *parent, const char *fmt, va_list ap) { - int i; + unsigned i; for (i = 0; i < parent->nodc; ++i) { _cf_warn_nodev(__whence, parent->nodv[i], NULL, fmt, ap); _cf_warn_childrenv(__whence, parent->nodv[i], fmt, ap); @@ -549,7 +548,7 @@ void _cf_warn_unsupported_node(struct __sourceloc __whence, const struct cf_om_n void _cf_warn_unsupported_children(struct __sourceloc __whence, const struct cf_om_node *parent) { - int i; + unsigned i; for (i = 0; i < parent->nodc; ++i) { if (parent->nodv[i]->text) _cf_warn_unsupported_node(__whence, parent->nodv[i]); @@ -572,7 +571,7 @@ strbuf strbuf_cf_flags(strbuf sb, int flags) { CFINVALID, "CFINVALID" }, { CFUNSUPPORTED, "CFUNSUPPORTED" }, }; - int i; + unsigned i; for (i = 0; i < NELS(flagdefs); ++i) { if (flags & flagdefs[i].flag) { if (strbuf_len(sb) != n) @@ -624,7 +623,7 @@ strbuf strbuf_cf_flag_reason(strbuf sb, int flags) { CFSUB(CFINVALID), "contains invalid element" }, { CFSUB(CFUNSUPPORTED), "contains unsupported element" }, }; - int i; + unsigned i; for (i = 0; i < NELS(flagdefs); ++i) { if (flags & flagdefs[i].flag) { if (strbuf_len(sb) != n) diff --git a/conf_parse.c b/conf_parse.c index 85ed0b89..c8065d55 100644 --- a/conf_parse.c +++ b/conf_parse.c @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include "constants.h" #include "log.h" #include "conf.h" @@ -212,7 +213,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. __ITEM(__element, (0 __flags)|__TEXT|__CHILDREN, cf_opt_##__repr(&strct->__element, child)) #define END_STRUCT \ { \ - int i; \ + unsigned i; \ for (i = 0; i < node->nodc; ++i) { \ if (node->nodv[i]->text && !(used[i] & __TEXT)) { \ cf_warn_unsupported_node(node->nodv[i]); \ @@ -246,7 +247,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. int (*keycmp)(const void *, const void *) = NULL; \ int (*validator)(const struct cf_om_node *, struct config_##__name *, int) = (NULL, ##__validator); \ int result = CFOK; \ - int i, n; \ + unsigned i, n; \ for (n = 0, i = 0; i < node->nodc && n < NELS(array->av); ++i) { \ const struct cf_om_node *child = node->nodv[i]; \ int ret = CFEMPTY; @@ -259,7 +260,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ret &= CF__FLAGS; \ result |= CFSUB(ret); \ if (ret == CFOK && (flags & __NO_DUPLICATES)) { \ - int j; \ + unsigned j; \ for (j = 0; j < n; ++j) { \ if (__cmpfunc __cmpfuncargs == 0) { \ cf_warn_duplicate_node(child, NULL); \ @@ -364,7 +365,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. int config_##__name##__get(const struct config_##__name *array, #define KEY_ATOM(__type, __keyrepr) \ const __type *key) { \ - int i; \ + unsigned i; \ for (i = 0; i < array->ac; ++i) \ if ((cf_cmp_##__keyrepr(key, &array->av[i].key)) == 0) \ return i; \ @@ -372,7 +373,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. } #define KEY_STRING(__strsize, __keyrepr) \ const char *key) { \ - int i; \ + unsigned i; \ for (i = 0; i < array->ac; ++i) \ if ((cf_cmp_##__keyrepr(&key[0], &array->av[i].key[0])) == 0) \ return i; \ @@ -417,7 +418,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define __ADD_CHILD(nodep, __elementstr) \ if ((i = cf_om_add_child(nodep, __elementstr)) == -1) \ return -1; \ - childp = &(*nodep)->nodv[i]; + childp = &(*nodep)->nodv[(unsigned)i]; #define __ATOM(nodep, __text) \ if (((*nodep)->text = str_edup(__text)) == NULL) \ return -1; @@ -515,7 +516,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. int cf_fmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *strct) { \ return cf_xfmt_config_##__name(parentp, strct, NULL); \ } \ - int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *strct, const struct config_##__name *dflt) { \ + int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *strct, const struct config_##__name *UNUSED(dflt)) { \ int result = CFOK; \ int ret; #define __FMT_TEXT(__repr, __eltname, __eltexpr, __defaultvar) \ @@ -561,11 +562,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. else { \ const char *funcname = NULL; #define __FMT_NODE_END \ - cf_om_remove_null_child(parentp, n); \ + cf_om_remove_null_child(parentp, (unsigned) n); \ if (ret != CFOK) \ WARNF("%s() returned %s", funcname, strbuf_str(strbuf_cf_flags(strbuf_alloca(300), ret))); \ - if (n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, n)) { \ - WHYF("%s() returned empty node at n=%d", funcname, n); \ + if ((unsigned)n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, (unsigned) n)) { \ + WHYF("%s() returned empty node at n=%u", funcname, (unsigned) n); \ ret = CFERROR; \ } \ } \ @@ -576,7 +577,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define NODE(__type, __element, __default, __repr, __flags, __comment) \ { \ __FMT_NODE_START(__element) \ - ret = cf_fmt_##__repr(&(*parentp)->nodv[n], &strct->__element); \ + ret = cf_fmt_##__repr(&(*parentp)->nodv[(unsigned)n], &strct->__element); \ funcname = "cf_fmt_" #__repr; \ __FMT_NODE_END \ } @@ -586,10 +587,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. if (#__dfllabel[0]) { \ struct config_##__structname dfl; \ cf_dfl_config_##__structname##_cf_##__dfllabel(&dfl); \ - ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[n], &strct->__element, &dfl); \ + ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &strct->__element, &dfl); \ funcname = "cf_xfmt_config_" #__structname; \ } else { \ - ret = cf_fmt_config_##__structname(&(*parentp)->nodv[n], &strct->__element); \ + ret = cf_fmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &strct->__element); \ funcname = "cf_fmt_config_" #__structname; \ } \ __FMT_NODE_END \ @@ -597,7 +598,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define NODE_STRUCT(__structname, __element, __repr, __flags, __dfllabel...) \ { \ __FMT_NODE_START(__element) \ - ret = cf_fmt_##__repr(&(*parentp)->nodv[n], &strct->__element); \ + ret = cf_fmt_##__repr(&(*parentp)->nodv[(unsigned)n], &strct->__element); \ funcname = "cf_fmt_" #__repr; \ __FMT_NODE_END \ } @@ -619,12 +620,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define SUB_STRUCT_DEFAULT(__name, __element, __dfllabel...) #define END_STRUCT_DEFAULT #define ARRAY(__name, __flags, __validator...) \ - int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *array, const struct config_##__name *dflt) { \ + int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *array, const struct config_##__name *UNUSED(dflt)) { \ return cf_fmt_config_##__name(parentp, array); \ } \ int cf_fmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *array) { \ int result = CFOK; \ - int i; \ + unsigned i; \ for (i = 0; i < array->ac; ++i) { #define __ARRAY_KEY(__keyfunc, __keyexpr) \ const char *key = NULL; \ @@ -646,15 +647,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. } \ if (ret == CFOK) { #define __ARRAY_VALUE(__valuefunc) \ - cf_om_remove_null_child(parentp, n); \ + cf_om_remove_null_child(parentp, (unsigned)n); \ if (ret != CFOK) \ WARNF(#__valuefunc "() returned %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(300), ret))); \ - if (n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, n)) { \ - WHYF(#__valuefunc "() returned empty node at n=%d", n); \ + if ((unsigned)n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, (unsigned)n)) { \ + WHYF(#__valuefunc "() returned empty node at n=%u", (unsigned)n); \ ret = CFERROR; \ } #define __ARRAY_TEXT(__valuefunc, __eltexpr) \ - ret = __valuefunc(&(*parentp)->nodv[n]->text, __eltexpr); \ + ret = __valuefunc(&(*parentp)->nodv[(unsigned)n]->text, __eltexpr); \ __ARRAY_VALUE(__valuefunc) #define END_ARRAY(__size) \ } \ @@ -676,19 +677,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define VALUE_STRING(__strsize, __eltrepr) \ __ARRAY_TEXT(cf_fmt_##__eltrepr, &array->av[i].value[0]) #define VALUE_NODE(__type, __eltrepr) \ - ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[n], &array->av[i].value); \ + ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[(unsigned)n], &array->av[i].value); \ __ARRAY_VALUE(cf_fmt_##__eltrepr) #define VALUE_SUB_STRUCT(__structname, __dfllabel...) \ if (#__dfllabel[0]) { \ struct config_##__structname dfl; \ cf_dfl_config_##__structname##_cf_##__dfllabel(&dfl); \ - ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[n], &array->av[i].value, &dfl); \ + ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &array->av[i].value, &dfl); \ } else { \ - ret = cf_fmt_config_##__structname(&(*parentp)->nodv[n], &array->av[i].value); \ + ret = cf_fmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &array->av[i].value); \ } \ __ARRAY_VALUE(cf_fmt_config_##__structname) #define VALUE_NODE_STRUCT(__structname, __eltrepr) \ - ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[n], &array->av[i].value); \ + ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[(unsigned)n], &array->av[i].value); \ __ARRAY_VALUE(cf_fmt_##__eltrepr) #include "conf_schema.h" #undef STRUCT @@ -757,7 +758,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define ARRAY(__name, __flags, __validator...) \ int cf_cmp_config_##__name(const struct config_##__name *a, const struct config_##__name *b) { \ int c; \ - int i; \ + unsigned i; \ for (i = 0; i < a->ac && i < b->ac; ++i) { #define KEY_ATOM(__type, __keyrepr) \ if ((c = cf_cmp_##__keyrepr(&a->av[i].key, &b->av[i].key))) \ diff --git a/conf_schema.c b/conf_schema.c index bf7ee794..2d27a6bb 100644 --- a/conf_schema.c +++ b/conf_schema.c @@ -504,7 +504,7 @@ int cf_cmp_ushort_nonzero(const unsigned short *a, const unsigned short *b) int vld_argv(const struct cf_om_node *parent, struct config_argv *array, int result) { unsigned short last_key = 0; - int i; + unsigned i; if (array->ac) { unsigned short last_key = array->av[0].key; for (i = 1; i < array->ac; ++i) { diff --git a/constants.h b/constants.h index 7af118b0..82938afd 100644 --- a/constants.h +++ b/constants.h @@ -19,7 +19,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef __SERVAL_DNA__CONSTANTS_H #define __SERVAL_DNA__CONSTANTS_H -#define NELS(a) (sizeof (a) / sizeof *(a)) +/* Useful macros not specific to Serval DNA + */ + +// Number of elements in an array (Warning: does not work if A is a pointer!). +#define NELS(A) (sizeof (A) / sizeof *(A)) + +// To suppress the "unused parameter" warning from -Wunused-parameter. +#ifdef __GNUC__ +# define UNUSED(x) x __attribute__((__unused__)) +#else +# define UNUSED(x) x +#endif /* Packet format: diff --git a/crypto.c b/crypto.c index e2e9fe7b..ff18eba9 100644 --- a/crypto.c +++ b/crypto.c @@ -102,10 +102,10 @@ int crypto_create_signature(unsigned char *key, } // sign the hash of a message, adding the signature to the end of the message buffer. -int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len) +int crypto_sign_message(struct subscriber *source, unsigned char *content, size_t buffer_len, size_t *content_len) { if (*content_len + SIGNATURE_BYTES > buffer_len) - return WHYF("Insufficient space in message buffer to add signature. %d, need %d",buffer_len, *content_len + SIGNATURE_BYTES); + return WHYF("Insufficient space in message buffer to add signature. %zu, need %zu",buffer_len, *content_len + SIGNATURE_BYTES); unsigned char *key=keyring_find_sas_private(keyring, &source->sid, NULL); if (!key) diff --git a/crypto.h b/crypto.h index 74190a7f..1e8953b2 100644 --- a/crypto.h +++ b/crypto.h @@ -30,7 +30,7 @@ int crypto_verify_message(struct subscriber *subscriber, unsigned char *message, int crypto_create_signature(unsigned char *key, unsigned char *content, int content_len, unsigned char *signature, int *sig_length); -int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len); +int crypto_sign_message(struct subscriber *source, unsigned char *content, size_t buffer_len, size_t *content_len); int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk); #endif diff --git a/directory_client.c b/directory_client.c index 5ac3ac19..92b4b314 100644 --- a/directory_client.c +++ b/directory_client.c @@ -75,19 +75,16 @@ static void directory_send(struct subscriber *directory_service, const sid_t *si // send a registration packet for each unlocked identity static void directory_send_keyring(struct subscriber *directory_service){ - int cn=0, in=0, kp=0, k2; - + unsigned cn=0, in=0, kp=0; for (; !keyring_sanitise_position(keyring, &cn, &in, &kp); ++kp){ keyring_identity *i = keyring->contexts[cn]->identities[in]; - if (i->keypairs[kp]->type == KEYTYPE_CRYPTOBOX){ const sid_t *sidp = (const sid_t *) i->keypairs[0]->public_key; - + unsigned k2; for(k2=0; k2 < i->keypair_count; k2++){ if (i->keypairs[k2]->type==KEYTYPE_DID){ const char *unpackedDid = (const char *) i->keypairs[k2]->private_key; const char *name = (const char *) i->keypairs[k2]->public_key; - directory_send(directory_service, sidp, unpackedDid, name); // send the first DID only break; diff --git a/dna_helper.c b/dna_helper.c index 66bceb96..049db02e 100644 --- a/dna_helper.c +++ b/dna_helper.c @@ -17,6 +17,36 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* + Portions Copyright (C) 2013 Petter Reinholdtsen + Some rights reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +#include #include #include #include @@ -88,8 +118,8 @@ static int dna_helper_started = 0; #define DECLARE_SCHED_ENT(FUNCTION, VARIABLE) \ static void FUNCTION(struct sched_ent *alarm); \ -static struct profile_total VARIABLE##_timing={.name="" #FUNCTION "",}; \ -static struct sched_ent VARIABLE = {.function = FUNCTION, .stats = & VARIABLE##_timing, .poll.fd = -1, }; +static struct profile_total VARIABLE##_timing={.name="" #FUNCTION "",._next=NULL,._initialised=0,.max_time=0,.total_time=0,.child_time=0,.calls=0}; \ +static struct sched_ent VARIABLE = {.function = FUNCTION, .stats = & VARIABLE##_timing, .poll={.fd=-1}}; DECLARE_SCHED_ENT(monitor_requests, sched_requests); DECLARE_SCHED_ENT(monitor_replies, sched_replies); @@ -183,7 +213,7 @@ dna_helper_start() // Construct argv[] for execv() and log messages. const char *argv[config.dna.helper.argv.ac + 2]; argv[0] = config.dna.helper.executable; - int i; + unsigned i; for (i = 0; i < config.dna.helper.argv.ac; ++i) argv[i + 1] = config.dna.helper.argv.av[i].value; argv[i + 1] = NULL; @@ -325,6 +355,7 @@ static void monitor_requests(struct sched_ent *alarm) strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_requests.poll.revents)) ); } + assert(alarm == &sched_requests); // On Linux, poll(2) returns ERR when the remote reader dies. On Mac OS X, poll(2) returns NVAL, // which is documented to mean the file descriptor is not open, but testing revealed that in this // case it is still open. See issue #5. @@ -451,6 +482,7 @@ static void monitor_replies(struct sched_ent *alarm) strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_replies.poll.revents)) ); } + assert(alarm == &sched_replies); if (sched_replies.poll.revents & POLLIN) { size_t remaining = reply_buffer + sizeof reply_buffer - reply_bufend; ssize_t nread = read_nonblock(sched_replies.poll.fd, reply_bufend, remaining); @@ -503,6 +535,7 @@ static void monitor_errors(struct sched_ent *alarm) strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_errors.poll.revents)) ); } + assert(alarm == &sched_errors); if (sched_errors.poll.revents & POLLIN) { char buffer[1024]; ssize_t nread = read_nonblock(sched_errors.poll.fd, buffer, sizeof buffer); @@ -521,6 +554,7 @@ static void monitor_errors(struct sched_ent *alarm) static void harvester(struct sched_ent *alarm) { + assert(alarm == &sched_harvester); // While the helper process appears to still be running, keep calling this function. // Otherwise, wait a while before re-starting the helper. if (dna_helper_harvest(0) <= 0) { @@ -541,6 +575,7 @@ static void harvester(struct sched_ent *alarm) static void restart_delayer(struct sched_ent *alarm) { + assert(alarm == &sched_restart); if (dna_helper_pid == 0) { if (config.debug.dnahelper) DEBUG("DNAHELPER re-enable restart"); @@ -550,6 +585,7 @@ static void restart_delayer(struct sched_ent *alarm) static void reply_timeout(struct sched_ent *alarm) { + assert(alarm == &sched_timeout); if (awaiting_reply) { WHY("DNAHELPER reply timeout"); dna_helper_kill(); diff --git a/fakeradio.c b/fakeradio.c index c0cb6a81..2ca3be4f 100644 --- a/fakeradio.c +++ b/fakeradio.c @@ -42,13 +42,13 @@ struct radio_state { int state; const char *name; char commandbuffer[128]; - int cb_len; + unsigned cb_len; unsigned char txbuffer[1280]; - int txb_len; - int tx_count; - int wait_count; + unsigned txb_len; + unsigned tx_count; + unsigned wait_count; unsigned char rxbuffer[512]; - int rxb_len; + unsigned rxb_len; int64_t last_char_ms; int64_t next_rssi_time_ms; int rssi_output; @@ -130,9 +130,9 @@ int processCommand(struct radio_state *s) return 1; } -int dump(char *name, unsigned char *addr, int len) +int dump(char *name, unsigned char *addr, size_t len) { - int i,j; + unsigned i,j; if (name) fprintf(stderr,"Dump of %s\n",name); for(i=0;irxb_len; + ssize_t wrote = s->rxb_len; if (wrote>8) wrote=8; if (s->last_char_ms) wrote = write(s->fd, s->rxbuffer, wrote); - if (wrote>0){ + if (wrote != -1){ log_time(); fprintf(stderr, "Wrote to %s\n", s->name); - dump(NULL, s->rxbuffer, wrote); - if (wrote < s->rxb_len) - bcopy(&s->rxbuffer[wrote], s->rxbuffer, s->rxb_len - wrote); - s->rxb_len -= wrote; + dump(NULL, s->rxbuffer, (size_t)wrote); + if ((size_t)wrote < s->rxb_len) + bcopy(&s->rxbuffer[(size_t)wrote], s->rxbuffer, s->rxb_len - (size_t)wrote); + s->rxb_len -= (size_t)wrote; } - return wrote; } int transmitter=0; @@ -286,21 +285,21 @@ int build_heartbeat(struct radio_state *s){ return 0; } -int transfer_bytes(struct radio_state *radios) +void transfer_bytes(struct radio_state *radios) { // if there's data to transmit, copy a radio packet from one device to the other int receiver = transmitter^1; struct radio_state *r = &radios[receiver]; struct radio_state *t = &radios[transmitter]; - int bytes=t->txb_len; + size_t bytes = t->txb_len; if (bytes > PACKET_SIZE) bytes = PACKET_SIZE; // try to send some number of whole mavlink frames from our buffer { - int p=0, send=0; - while(p < bytes){ + size_t p=0, send=0; + while (p < bytes){ if (t->txbuffer[p]==MAVLINK10_STX){ // a mavlink header @@ -315,7 +314,7 @@ int transfer_bytes(struct radio_state *radios) break; // how big is this mavlink frame? - int size = t->txbuffer[p+1]; + size_t size = t->txbuffer[p+1]; // if the size is valid, try to send the whole packet at once if (size <= PACKET_SIZE - MAVLINK_HDR){ @@ -359,7 +358,7 @@ int transfer_bytes(struct radio_state *radios) fprintf(stderr, "Transferring %d byte packet from %s to %s\n", bytes, t->name, r->name); } - int i, j; + unsigned i, j; int dropped=0; // preamble length in bits that must arrive intact @@ -394,14 +393,13 @@ int transfer_bytes(struct radio_state *radios) // set the wait time for the next transmission next_transmit_time = gettime_ms() + 5 + bytes/chars_per_ms; - if (bytes==0 || --t->tx_count<=0){ + if (bytes==0 || t->tx_count == 0 || --t->tx_count == 0){ // swap who's turn it is to transmit after sending 3 packets or running out of data. transmitter = receiver; r->tx_count=3; // add Tx->Rx change time (it's about 40ms between receiving empty packets) next_transmit_time+=15; } - return bytes; } int calc_ber(double target_packet_fraction) diff --git a/fdqueue.c b/fdqueue.c index 03592167..de18178b 100644 --- a/fdqueue.c +++ b/fdqueue.c @@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* + Portions Copyright (C) 2013 Petter Reinholdtsen + Some rights reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + #include "fdqueue.h" #include "conf.h" #include "str.h" @@ -29,7 +58,7 @@ int fdcount=0; struct sched_ent *fd_callbacks[MAX_WATCHED_FDS]; struct sched_ent *next_alarm=NULL; struct sched_ent *next_deadline=NULL; -struct profile_total poll_stats={NULL,0,"Idle (in poll)",0,0,0}; +struct profile_total poll_stats={NULL,0,"Idle (in poll)",0,0,0,0}; #define alloca_alarm_name(alarm) ((alarm)->stats ? alloca_str_toprint((alarm)->stats->name) : "Unnamed") diff --git a/fdqueue.h b/fdqueue.h index 9aab47b5..5e3f48d5 100644 --- a/fdqueue.h +++ b/fdqueue.h @@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* + Portions Copyright (C) 2013 Petter Reinholdtsen + Some rights reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + #ifndef __SERVAL_DNA__FDQUEUE_H #define __SERVAL_DNA__FDQUEUE_H @@ -83,7 +112,7 @@ int fd_func_exit(struct __sourceloc, struct call_stats *this_call); void dump_stack(int log_level); unsigned fd_depth(); -#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \ +#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0,0}; \ struct call_stats _this_call={.totals=&_aggregate_stats}; \ fd_func_enter(__HERE__, &_this_call); diff --git a/fec-3.0.1/init_rs.h b/fec-3.0.1/init_rs.h index 2b2ae98c..a56752ab 100644 --- a/fec-3.0.1/init_rs.h +++ b/fec-3.0.1/init_rs.h @@ -10,7 +10,7 @@ rs = NULL; /* Check parameter ranges */ - if(symsize < 0 || symsize > 8*sizeof(data_t)){ + if(symsize < 0 || symsize > (int)(8*sizeof(data_t))){ goto done; } diff --git a/http_server.c b/http_server.c index 1a2193a2..adaa6cae 100644 --- a/http_server.c +++ b/http_server.c @@ -1593,7 +1593,7 @@ static void http_request_send_response(struct http_request *r) if (r->phase != PAUSE) http_request_set_idle_timeout(r); // If we wrote less than we tried, then go back to polling, otherwise keep generating content. - if (written < (size_t) unsent) + if ((size_t) written < (size_t) unsent) return; } if (r->debug_flag && *r->debug_flag) diff --git a/keyring.c b/keyring.c index 1593d315..1260fd6d 100644 --- a/keyring.c +++ b/keyring.c @@ -238,10 +238,12 @@ static void wipestr(char *str) *str++ = ' '; } -void keyring_release_identity(keyring_file *k, int cn, int id){ +void keyring_release_identity(keyring_file *k, unsigned cn, unsigned id) +{ if (config.debug.keyring) - DEBUGF("Releasing k=%p, cn=%d, id=%d", k, cn, id); + DEBUGF("Releasing k=%p, cn=%u, id=%u", k, cn, id); keyring_context *c=k->contexts[cn]; + assert(c->identity_count > 0); c->identity_count--; keyring_free_identity(c->identities[id]); if (id!=c->identity_count) @@ -249,6 +251,7 @@ void keyring_release_identity(keyring_file *k, int cn, int id){ c->identities[c->identity_count]=NULL; if (c->identity_count==0){ keyring_free_context(c); + assert(k->context_count > 0); k->context_count --; if (cn!=k->context_count) k->contexts[cn] = k->contexts[k->context_count]; @@ -258,8 +261,8 @@ void keyring_release_identity(keyring_file *k, int cn, int id){ void keyring_release_subscriber(keyring_file *k, const sid_t *sid) { - int cn=0,in=0,kp=0; - if (keyring_find_sid(keyring, &cn, &in, &kp, sid) + unsigned cn=0, in=0, kp=0; + if (keyring_find_sid(k, &cn, &in, &kp, sid) && keyring->contexts[cn]->identities[in]->subscriber != my_subscriber) keyring_release_identity(keyring, cn, in); } @@ -328,7 +331,7 @@ int keyring_enter_keyringpin(keyring_file *k, const char *pin) return WHY("Too many loaded contexts already"); if (k->context_count < 1) return WHY("Cannot enter PIN without keyring salt being available"); - int cn; + unsigned cn; for (cn = 0; cn < k->context_count; ++cn) if (strcmp(k->contexts[cn]->KeyRingPin, pin) == 0) return cn; @@ -444,7 +447,7 @@ struct keytype { size_t packed_size; void (*creator)(keypair *); int (*packer)(const keypair *, struct rotbuf *); - int (*unpacker)(keypair *, struct rotbuf *, int); + int (*unpacker)(keypair *, struct rotbuf *, size_t); void (*dumper)(const keypair *, XPRINTF, int); int (*loader)(keypair *, const char *); }; @@ -630,14 +633,15 @@ static int load_unknown(keypair *kp, const char *text) return 0; } -static int unpack_private_public(keypair *kp, struct rotbuf *rb, int key_length) +static int unpack_private_public(keypair *kp, struct rotbuf *rb, size_t key_length) { + assert(key_length == kp->private_key_len + kp->public_key_len); rotbuf_getbuf(rb, kp->private_key, kp->private_key_len); rotbuf_getbuf(rb, kp->public_key, kp->public_key_len); return 0; } -static int unpack_private_only(keypair *kp, struct rotbuf *rb, int key_length) +static int unpack_private_only(keypair *kp, struct rotbuf *rb, size_t key_length) { if (!kp->private_key){ kp->private_key_len = key_length; @@ -648,7 +652,7 @@ static int unpack_private_only(keypair *kp, struct rotbuf *rb, int key_length) return 0; } -static int unpack_public_only(keypair *kp, struct rotbuf *rb, int key_length) +static int unpack_public_only(keypair *kp, struct rotbuf *rb, size_t key_length) { if (!kp->public_key){ kp->public_key_len = key_length; @@ -659,8 +663,9 @@ static int unpack_public_only(keypair *kp, struct rotbuf *rb, int key_length) return 0; } -static int unpack_cryptobox(keypair *kp, struct rotbuf *rb, int key_length) +static int unpack_cryptobox(keypair *kp, struct rotbuf *rb, size_t key_length) { + assert(key_length == kp->private_key_len); rotbuf_getbuf(rb, kp->private_key, kp->private_key_len); if (!rb->wrap) _derive_scalarmult_public(kp->public_key, kp->private_key); @@ -675,7 +680,7 @@ static int pack_did_name(const keypair *kp, struct rotbuf *rb) return pack_private_public(kp, rb); } -static int unpack_did_name(keypair *kp, struct rotbuf *rb, int key_length) +static int unpack_did_name(keypair *kp, struct rotbuf *rb, size_t key_length) { if (unpack_private_public(kp, rb, key_length) == -1) return -1; @@ -683,7 +688,7 @@ static int unpack_did_name(keypair *kp, struct rotbuf *rb, int key_length) return strnchr((const char *)kp->public_key, kp->public_key_len, '\0') == NULL ? -1 : 0; } -static void dump_did_name(const keypair *kp, XPRINTF xpf, int include_secret) +static void dump_did_name(const keypair *kp, XPRINTF xpf, int UNUSED(include_secret)) { xprintf(xpf, " DID=%s", alloca_str_toprint_quoted((const char *)kp->private_key, "\"\"")); xprintf(xpf, " Name=%s", alloca_str_toprint_quoted((const char *)kp->public_key, "\"\"")); @@ -958,9 +963,9 @@ static int cmp_keypair(const keypair *a, const keypair *b) if (c == 0 && a->public_key_len) { assert(a->public_key != NULL); assert(b->public_key != NULL); - int len=a->public_key_len; - if (len>b->public_key_len) - len=b->public_key_len; + size_t len = a->public_key_len; + if (len > b->public_key_len) + len = b->public_key_len; c = memcmp(a->public_key, b->public_key, len); if (c==0 && a->public_key_len!=b->public_key_len) c = a->public_key_len - b->public_key_len; @@ -968,9 +973,9 @@ static int cmp_keypair(const keypair *a, const keypair *b) if (c == 0 && a->private_key_len) { assert(a->private_key != NULL); assert(b->private_key != NULL); - int len=a->private_key_len; - if (len>b->private_key_len) - len=b->private_key_len; + size_t len = a->private_key_len; + if (len > b->private_key_len) + len = b->private_key_len; c = memcmp(a->private_key, b->private_key, len); if (c==0 && a->private_key_len!=b->private_key_len) c = a->private_key_len - b->private_key_len; @@ -1168,7 +1173,7 @@ static int keyring_decrypt_pkr(keyring_file *k, unsigned cn, const char *pin, in goto kdp_safeexit; } // Add any unlocked subscribers to our memory table, flagged as local SIDs. - int i=0; + unsigned i; for (i=0;ikeypair_count;i++){ if (id->keypairs[i]->type == KEYTYPE_CRYPTOBOX) { add_subscriber(id, i); @@ -1237,7 +1242,7 @@ int keyring_enter_pin(keyring_file *k, const char *pin) if (b->bitmap[byte]&(1<context_count; ++cn) if (keyring_decrypt_pkr(k, cn, pin, slot) == 0) ++identitiesFound; @@ -1444,7 +1449,7 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name) if (!name) name="Mr. Smith"; /* Find where to put it */ - int i; + unsigned i; for(i=0;ikeypair_count;i++) if (id->keypairs[i]->type==KEYTYPE_DID) { if (config.debug.keyring) @@ -1461,27 +1466,27 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name) if (config.debug.keyring) DEBUG("Created DID record for identity"); } - + /* Store DID unpacked for ease of searching */ - int len=strlen(did); + size_t len=strlen(did); if (len>31) len=31; bcopy(did,&id->keypairs[i]->private_key[0],len); bzero(&id->keypairs[i]->private_key[len],32-len); - len=strlen(name); - if (len>63) + len=strlen(name); + if (len>63) len=63; bcopy(name,&id->keypairs[i]->public_key[0],len); bzero(&id->keypairs[i]->public_key[len],64-len); - + if (config.debug.keyring){ dump("storing did",&id->keypairs[i]->private_key[0],32); dump("storing name",&id->keypairs[i]->public_key[0],64); - } + } return 0; } -int keyring_find_did(const keyring_file *k, int *cn, int *in, int *kp, const char *did) +int keyring_find_did(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *did) { for(;keyring_next_keytype(k,cn,in,kp,KEYTYPE_DID);++(*kp)) { /* Compare DIDs */ @@ -1527,8 +1532,8 @@ int keyring_pack_tag(unsigned char *packed, size_t *packed_len, const char *name int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigned char *value, size_t length) { - int i; - for(i=0;ikeypair_count;i++){ + unsigned i; + for (i=0;ikeypair_count;i++){ const char *tag_name; const unsigned char *tag_value; size_t tag_length; @@ -1570,7 +1575,7 @@ int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigne return 0; } -int keyring_find_public_tag(const keyring_file *k, int *cn, int *in, int *kp, const char *name, const unsigned char **value, size_t *length) +int keyring_find_public_tag(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *name, const unsigned char **value, size_t *length) { for(;keyring_next_keytype(k,cn,in,kp,KEYTYPE_PUBLIC_TAG);++(*kp)) { keypair *keypair=k->contexts[*cn]->identities[*in]->keypairs[*kp]; @@ -1585,7 +1590,7 @@ int keyring_find_public_tag(const keyring_file *k, int *cn, int *in, int *kp, co return 0; } -int keyring_find_public_tag_value(const keyring_file *k, int *cn, int *in, int *kp, const char *name, const unsigned char *value, size_t length) +int keyring_find_public_tag_value(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *name, const unsigned char *value, size_t length) { const unsigned char *stored_value; size_t stored_length; @@ -1596,16 +1601,16 @@ int keyring_find_public_tag_value(const keyring_file *k, int *cn, int *in, int * return 0; } -int keyring_identity_find_keytype(const keyring_file *k, int cn, int in, int keytype) +int keyring_identity_find_keytype(const keyring_file *k, unsigned cn, unsigned in, unsigned keytype) { - int kp; - for (kp = 0; kp < keyring->contexts[cn]->identities[in]->keypair_count; ++kp) - if (keyring->contexts[cn]->identities[in]->keypairs[kp]->type == keytype) + unsigned kp; + for (kp = 0; kp < k->contexts[cn]->identities[in]->keypair_count; ++kp) + if (k->contexts[cn]->identities[in]->keypairs[kp]->type == keytype) return kp; return -1; } -int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int keytype) +int keyring_next_keytype(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, unsigned keytype) { for (; keyring_sanitise_position(k, cn, in, kp) == 0; ++*kp) if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type == keytype) @@ -1613,15 +1618,13 @@ int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int k return 0; } -int keyring_next_identity(const keyring_file *k, int *cn, int *in, int *kp) +int keyring_next_identity(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp) { return keyring_next_keytype(k, cn, in, kp, KEYTYPE_CRYPTOBOX); } -int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp) +int keyring_sanitise_position(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp) { - if (!k) - return 1; /* Sanity check passed in position */ while(1){ if ((*cn)>=k->context_count) @@ -1646,15 +1649,13 @@ int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp) unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsigned char **sas_public_out) { IN(); - int cn=0,in=0,kp=0; - + unsigned cn=0, in=0, kp=0; if (!keyring_find_sid(k,&cn,&in,&kp,sidp)) RETURNNULL(WHYNULL("Could not find SID in keyring, so can't find SAS")); - - kp = keyring_identity_find_keytype(k, cn, in, KEYTYPE_CRYPTOSIGN); - if (kp==-1) + int kpi = keyring_identity_find_keytype(k, cn, in, KEYTYPE_CRYPTOSIGN); + if (kpi == -1) RETURNNULL(WHYNULL("Identity lacks SAS")); - + kp = (unsigned) kpi; unsigned char *sas_private= k->contexts[cn]->identities[in]->keypairs[kp]->private_key; unsigned char *sas_public= @@ -1668,7 +1669,8 @@ unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsi } if (config.debug.keyring) DEBUGF("Found SAS entry for %s*", alloca_tohex(sidp->binary, 7)); - if (sas_public_out) *sas_public_out=sas_public; + if (sas_public_out) + *sas_public_out = sas_public; RETURN(sas_private); OUT(); } @@ -1789,10 +1791,10 @@ int keyring_send_unlock(struct subscriber *subscriber) mdp.out.src.port=MDP_PORT_KEYMAPREQUEST; mdp.out.src.sid = my_subscriber->sid; mdp.out.payload[0]=UNLOCK_REQUEST; - int len=1; + size_t len = 1; if (crypto_sign_message(subscriber, mdp.out.payload, sizeof(mdp.out.payload), &len)) return -1; - mdp.out.payload_length=len; + mdp.out.payload_length = len; return overlay_mdp_dispatch(&mdp, NULL); } @@ -1838,7 +1840,7 @@ static int keyring_respond_challenge(struct subscriber *subscriber, overlay_mdp_ mdp.out.src.sid = my_subscriber->sid; mdp.out.payload[0]=UNLOCK_RESPONSE; bcopy(&req->out.payload[1], &mdp.out.payload[1], req->out.payload_length -1); - int len=req->out.payload_length; + size_t len = req->out.payload_length; if (crypto_sign_message(subscriber, mdp.out.payload, sizeof(mdp.out.payload), &len)) return -1; mdp.out.payload_length=len; @@ -1937,7 +1939,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){ return 0; } -int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const sid_t *sidp) +int keyring_find_sid(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const sid_t *sidp) { for(; keyring_next_keytype(k,cn,in,kp,KEYTYPE_CRYPTOBOX); ++(*kp)) { if (memcmp(sidp->binary, k->contexts[*cn]->identities[*in]->keypairs[*kp]->public_key, SID_SIZE) == 0) @@ -1949,7 +1951,7 @@ int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const sid void keyring_identity_extract(const keyring_identity *id, const sid_t **sidp, const char **didp, const char **namep) { int todo = (sidp ? 1 : 0) | (didp ? 2 : 0) | (namep ? 4 : 0); - int kpn; + unsigned kpn; for (kpn = 0; todo && kpn < id->keypair_count; ++kpn) { keypair *kp = id->keypairs[kpn]; switch (kp->type) { @@ -2073,7 +2075,7 @@ struct nm_record { unsigned char nm_bytes[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; }; -int nm_slots_used=0; +unsigned nm_slots_used=0; /* 512 x 96 bytes = 48KB, not too big */ #define NM_CACHE_SLOTS 512 struct nm_record nm_cache[NM_CACHE_SLOTS]; @@ -2085,9 +2087,8 @@ unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknow if (!unknown_sidp) { RETURNNULL(WHYNULL("unknown pub key is null")); } if (!keyring) { RETURNNULL(WHYNULL("keyring is null")); } - int i; - /* See if we have it cached already */ + unsigned i; for(i=0;iconfig == &config.log.android) { diff --git a/lsif.c b/lsif.c index 10065455..e549f1ab 100644 --- a/lsif.c +++ b/lsif.c @@ -124,7 +124,7 @@ int lsif(void) { char buf[8192]; struct ifconf ifc; - int sck, nInterfaces, ofs; + int sck; struct ifreq *ifr; struct in_addr addr, netmask; @@ -138,7 +138,7 @@ lsif(void) { } /* Query available interfaces. */ - ifc.ifc_len = sizeof(buf); + ifc.ifc_len = sizeof buf; ifc.ifc_buf = buf; if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) { WHY_perror("ioctl(SIOCGIFCONF)"); @@ -147,10 +147,9 @@ lsif(void) { } /* Iterate through the list of interfaces. */ - nInterfaces = 0; - ofs = 0; - - while (ofs < ifc.ifc_len && ofs < sizeof(buf)) { + unsigned nInterfaces = 0; + unsigned ofs = 0; + while (ofs < (unsigned)ifc.ifc_len && ofs < sizeof buf) { ifr = (struct ifreq *)(ifc.ifc_ifcu.ifcu_buf + ofs); ofs += _SIZEOF_ADDR_IFREQ(*ifr); @@ -183,7 +182,7 @@ lsif(void) { nInterfaces++; } - if (config.debug.overlayinterfaces) DEBUGF("Examined %d interface addresses", nInterfaces); + if (config.debug.overlayinterfaces) DEBUGF("Examined %u interface addresses", nInterfaces); close(sck); return 0; diff --git a/mdp_client.c b/mdp_client.c index 2cb7e0e1..bc02fb20 100644 --- a/mdp_client.c +++ b/mdp_client.c @@ -119,8 +119,10 @@ ssize_t mdp_recv(int socket, struct mdp_header *header, uint8_t *payload, ssize_ }; ssize_t len = recvmsg(socket, &hdr, 0); - if (lenread); if (ret == 1) - WARNF("Payload was not found for manifest %s, %"PRId64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version); + WARNF("Payload was not found for manifest %s, %"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version); if (ret != 0) return ret; assert(m->filesize != RHIZOME_SIZE_UNSET); @@ -742,7 +742,7 @@ int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_context return 0; } -int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_context *context) +int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { const char *my_sidhex, *their_sidhex, *message; if (cli_arg(parsed, "sender_sid", &my_sidhex, str_is_subscriber_id, "") == -1 @@ -977,7 +977,7 @@ static int mark_read(struct conversations *conv, const sid_t *their_sid, const c return ret; } -int app_meshms_mark_read(const struct cli_parsed *parsed, struct cli_context *context) +int app_meshms_mark_read(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { const char *my_sidhex, *their_sidhex, *offset_str; if (cli_arg(parsed, "sender_sid", &my_sidhex, str_is_subscriber_id, "") == -1 diff --git a/monitor-cli.c b/monitor-cli.c index 506ece60..b1e6b2bf 100644 --- a/monitor-cli.c +++ b/monitor-cli.c @@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "cli.h" #include "monitor-client.h" -int remote_print(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){ +int remote_print(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *UNUSED(context)) +{ int i; printf("%s",cmd); for (i=0;ireachable&REACHABLE) monitor_announce_peer(&subscriber->sid); @@ -376,7 +405,7 @@ static int monitor_set(const struct cli_parsed *parsed, struct cli_context *cont c->flags|=MONITOR_VOMP; // store the list of supported codecs against the monitor connection, // since we need to forget about them when the client disappears. - int i; + unsigned i; for (i = 2; i < parsed->argc; ++i) { int codec = atoi(parsed->args[i]); if (codec>=0 && codec <=255) @@ -462,7 +491,7 @@ static int monitor_call(const struct cli_parsed *parsed, struct cli_context *con return 0; } -static int monitor_call_ring(const struct cli_parsed *parsed, struct cli_context *context) +static int monitor_call_ring(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { struct vomp_call_state *call=vomp_find_call_by_session(strtol(parsed->args[1],NULL,16)); if (!call) @@ -472,7 +501,7 @@ static int monitor_call_ring(const struct cli_parsed *parsed, struct cli_context return 0; } -static int monitor_call_pickup(const struct cli_parsed *parsed, struct cli_context *context) +static int monitor_call_pickup(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { struct vomp_call_state *call=vomp_find_call_by_session(strtol(parsed->args[1],NULL,16)); if (!call) @@ -500,7 +529,7 @@ static int monitor_call_audio(const struct cli_parsed *parsed, struct cli_contex return 0; } -static int monitor_call_hangup(const struct cli_parsed *parsed, struct cli_context *context) +static int monitor_call_hangup(const struct cli_parsed *parsed, struct cli_context *UNUSED(context)) { struct vomp_call_state *call=vomp_find_call_by_session(strtol(parsed->args[1],NULL,16)); if (!call) @@ -518,7 +547,7 @@ static int monitor_call_dtmf(const struct cli_parsed *parsed, struct cli_context return monitor_write_error(c,"Invalid call token"); const char *digits = parsed->args[2]; - int i; + unsigned i; for(i=0;i","","[