diff --git a/NEWS b/NEWS index eaa175ba..23e5652c 100644 --- a/NEWS +++ b/NEWS @@ -328,6 +328,7 @@ To be released as 0.11.4. * minor bug 461: ensure contrast in blank areas, to keep the cursor visible * minor bug 928: properly display no-break spaces in a UTF-8 document if the terminal uses some other charset +* minor: don't assume sizeof(int)==4 in bittorrent * trivial bug 947: document.html.wrap_nbsp also affects text in tables * trivial bug 997: fix unlikely stack corruption in active FTP * build bug 950: fix ``config/install-sh: No such file or directory'' diff --git a/src/document/css/css.c b/src/document/css/css.c index 4bc80ea3..fdd4dded 100644 --- a/src/document/css/css.c +++ b/src/document/css/css.c @@ -150,7 +150,7 @@ import_css(struct css_stylesheet *css, struct uri *uri) static void import_css_file(struct css_stylesheet *css, struct uri *base_uri, - unsigned char *url, int urllen) + const unsigned char *url, int urllen) { struct string string, filename; diff --git a/src/document/css/scanner.c b/src/document/css/scanner.c index cb927a2f..361b1a41 100644 --- a/src/document/css/scanner.c +++ b/src/document/css/scanner.c @@ -158,7 +158,7 @@ scan_css_token(struct scanner *scanner, struct scanner_token *token) type = CSS_TOKEN_NUMBER; } else { - unsigned char *ident = string; + const unsigned char *ident = string; scan_css(scanner, string, CSS_CHAR_IDENT); type = map_scanner_string(scanner, ident, string, @@ -251,7 +251,7 @@ scan_css_token(struct scanner *scanner, struct scanner_token *token) } else if (first_char == '@') { /* Compose token containing @ */ if (is_css_ident_start(*string)) { - unsigned char *ident = string; + const unsigned char *ident = string; /* Scan both ident start and ident */ scan_css(scanner, string, CSS_CHAR_IDENT); diff --git a/src/document/css/stylesheet.c b/src/document/css/stylesheet.c index a0ec6903..7cdd14a6 100644 --- a/src/document/css/stylesheet.c +++ b/src/document/css/stylesheet.c @@ -50,7 +50,7 @@ struct css_selector * init_css_selector(struct css_selector_set *sels, enum css_selector_type type, enum css_selector_relation relation, - unsigned char *name, int namelen) + const unsigned char *name, int namelen) { struct css_selector *selector; @@ -97,7 +97,7 @@ struct css_selector * get_css_selector(struct css_selector_set *sels, enum css_selector_type type, enum css_selector_relation rel, - unsigned char *name, int namelen) + const unsigned char *name, int namelen) { struct css_selector *selector = NULL; diff --git a/src/document/css/stylesheet.h b/src/document/css/stylesheet.h index 79602307..01f0e9e5 100644 --- a/src/document/css/stylesheet.h +++ b/src/document/css/stylesheet.h @@ -96,7 +96,7 @@ struct css_selector { struct css_stylesheet; typedef void (*css_stylesheet_importer_T)(struct css_stylesheet *, struct uri *, - unsigned char *url, int urllen); + const unsigned char *url, int urllen); /** The struct css_stylesheet describes all the useful data that was extracted * from the CSS source. Currently we don't cache anything but the default user @@ -140,7 +140,7 @@ void done_css_stylesheet(struct css_stylesheet *css); struct css_selector *get_css_selector(struct css_selector_set *set, enum css_selector_type type, enum css_selector_relation rel, - unsigned char *name, int namelen); + const unsigned char *name, int namelen); #define get_css_base_selector(stylesheet, type, rel, name, namelen) \ get_css_selector((stylesheet) ? &(stylesheet)->selectors : NULL, \ @@ -161,7 +161,7 @@ struct css_selector *find_css_selector(struct css_selector_set *set, struct css_selector *init_css_selector(struct css_selector_set *set, enum css_selector_type type, enum css_selector_relation relation, - unsigned char *name, int namelen); + const unsigned char *name, int namelen); /** Add all properties from the list to the given @a selector. */ void add_selector_properties(struct css_selector *selector, diff --git a/src/document/css/value.c b/src/document/css/value.c index e08960b8..a58f0521 100644 --- a/src/document/css/value.c +++ b/src/document/css/value.c @@ -40,7 +40,7 @@ css_parse_color_value(struct css_property_info *propinfo, /* The first two args are terminated by ',' and the * last one by ')'. */ unsigned char paskynator = shift ? ',' : ')'; - unsigned char *nstring = token->string; + const unsigned char *nstring = token->string; int part; /* Are the current and next token valid? */ diff --git a/src/document/html/internal.h b/src/document/html/internal.h index c656660f..ff2224e2 100644 --- a/src/document/html/internal.h +++ b/src/document/html/internal.h @@ -143,6 +143,6 @@ unsigned char *get_target(struct document_options *options, unsigned char *a); void import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri, - unsigned char *url, int len); + const unsigned char *unterminated_url, int len); #endif diff --git a/src/document/html/parser.c b/src/document/html/parser.c index 54fe6d52..ecafb631 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -188,9 +188,10 @@ add_fragment_identifier(struct html_context *html_context, #ifdef CONFIG_CSS void import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri, - unsigned char *url, int len) + const unsigned char *unterminated_url, int len) { struct html_context *html_context = css->import_data; + unsigned char *url; unsigned char *import_url; struct uri *uri; @@ -201,7 +202,9 @@ import_css_stylesheet(struct css_stylesheet *css, struct uri *base_uri, || !html_context->options->css_import) return; - url = memacpy(url, len); + /* unterminated_url might not end with '\0', but join_urls + * requires that, so make a copy. */ + url = memacpy(unterminated_url, len); if (!url) return; /* HTML urls should already be fine but we can.t detect them. */ diff --git a/src/protocol/bittorrent/bencoding.c b/src/protocol/bittorrent/bencoding.c index 237f3af7..7f0b320d 100644 --- a/src/protocol/bittorrent/bencoding.c +++ b/src/protocol/bittorrent/bencoding.c @@ -327,7 +327,7 @@ check_bencoding_dictionary_entry(struct scanner *scanner, static off_t parse_bencoding_integer(struct scanner_token *token) { - unsigned char *string = token->string; + const unsigned char *string = token->string; int pos = 0, length = token->length; off_t integer = 0; int sign = 1; @@ -340,9 +340,13 @@ parse_bencoding_integer(struct scanner_token *token) } for (; pos < length && isdigit(string[pos]); pos++) { - if (integer > (off_t) integer * 10) + off_t newint = integer * 10 + string[pos] - '0'; + + /* Check for overflow. This assumes wraparound, + * even though C does not guarantee that. */ + if (newint / 10 != integer) return 0; - integer = (off_t) integer * 10 + string[pos] - '0'; + integer = newint; } if (sign == -1) @@ -352,7 +356,8 @@ parse_bencoding_integer(struct scanner_token *token) } static unsigned char * -normalize_bencoding_path(unsigned char *path, int pathlen, int *malicious) +normalize_bencoding_path(const unsigned char *path, int pathlen, + int *malicious) { struct string string; @@ -735,7 +740,7 @@ parse_bittorrent_metafile(struct bittorrent_meta *meta, struct string *metafile) case BENCODING_TOKEN_INFO: { - unsigned char *start = value->string; + const unsigned char *start = value->string; struct scanner_token *token; enum bittorrent_state state; @@ -881,8 +886,9 @@ parse_bencoding_peers_string(struct bittorrent_connection *bittorrent, struct scanner *scanner) { struct scanner_token *token = get_scanner_token(scanner); - unsigned char *pos; - unsigned char *last_peer_info_start = token->string + token->length - 6; + const unsigned char *pos; + const unsigned char *last_peer_info_start + = token->string + token->length - 6; enum bittorrent_state state = BITTORRENT_STATE_OK; assert(get_scanner_token(scanner)->type == BENCODING_TOKEN_STRING); diff --git a/src/protocol/bittorrent/common.c b/src/protocol/bittorrent/common.c index d9fe3ecb..a0a9ec1c 100644 --- a/src/protocol/bittorrent/common.c +++ b/src/protocol/bittorrent/common.c @@ -213,7 +213,7 @@ get_peer_from_bittorrent_pool(struct bittorrent_connection *bittorrent, enum bittorrent_state add_peer_to_bittorrent_pool(struct bittorrent_connection *bittorrent, bittorrent_id_T id, int port, - unsigned char *ip, int iplen) + const unsigned char *ip, int iplen) { struct bittorrent_peer *peer; diff --git a/src/protocol/bittorrent/common.h b/src/protocol/bittorrent/common.h index 5ea507e1..9d44b761 100644 --- a/src/protocol/bittorrent/common.h +++ b/src/protocol/bittorrent/common.h @@ -368,7 +368,7 @@ bittorrent_id_is_known(struct bittorrent_connection *bittorrent, enum bittorrent_state add_peer_to_bittorrent_pool(struct bittorrent_connection *bittorrent, bittorrent_id_T id, int port, - unsigned char *ip, int iplen); + const unsigned char *ip, int iplen); struct bittorrent_peer * get_peer_from_bittorrent_pool(struct bittorrent_connection *bittorrent, diff --git a/src/protocol/bittorrent/piececache.c b/src/protocol/bittorrent/piececache.c index 3ef61c5b..f448a868 100644 --- a/src/protocol/bittorrent/piececache.c +++ b/src/protocol/bittorrent/piececache.c @@ -1080,7 +1080,7 @@ bittorrent_resume_writer(void *data, int fd) uint32_t piece; memcpy(&metafile.length, data, sizeof(metafile.length)); - metafile.source = (unsigned char *) data + 4; + metafile.source = (unsigned char *) data + sizeof(metafile.length); if (parse_bittorrent_metafile(&meta, &metafile) != BITTORRENT_STATE_OK) { done_bittorrent_meta(&meta); diff --git a/src/util/color.c b/src/util/color.c index 5b7872a5..d6684ebb 100644 --- a/src/util/color.c +++ b/src/util/color.c @@ -82,7 +82,7 @@ free_colors_lookup(void) } int -decode_color(unsigned char *str, int slen, color_T *color) +decode_color(const unsigned char *str, int slen, color_T *color) { if (*str == '#' && (slen == 7 || slen == 4)) { unsigned char buffer[7]; diff --git a/src/util/color.h b/src/util/color.h index 80ad9f8b..52f7353c 100644 --- a/src/util/color.h +++ b/src/util/color.h @@ -13,7 +13,7 @@ struct color_pair { /** Decode the color string. * The color string can either contain '@#FF0044' style declarations or * color names. */ -int decode_color(unsigned char *str, int slen, color_T *color); +int decode_color(const unsigned char *str, int slen, color_T *color); /** Returns a string containing the color info. If no 'English' name can be * found the hex color (@#rrggbb) is returned in the given buffer. */ diff --git a/src/util/fastfind.c b/src/util/fastfind.c index 9279dc59..17ac97ed 100644 --- a/src/util/fastfind.c +++ b/src/util/fastfind.c @@ -590,7 +590,8 @@ return_error: } while (0) void * -fastfind_search(struct fastfind_index *index, unsigned char *key, int key_len) +fastfind_search(struct fastfind_index *index, + const unsigned char *key, int key_len) { struct ff_node *current; struct fastfind_info *info; diff --git a/src/util/fastfind.h b/src/util/fastfind.h index 27a03407..a6b85585 100644 --- a/src/util/fastfind.h +++ b/src/util/fastfind.h @@ -49,7 +49,8 @@ struct fastfind_index *fastfind_index(struct fastfind_index *index, enum fastfin /** Search the index for @a key with length @a key_len using the * @a index' handle created with fastfind_index(). * @relates fastfind_index */ -void *fastfind_search(struct fastfind_index *index, unsigned char *key, int key_len); +void *fastfind_search(struct fastfind_index *index, + const unsigned char *key, int key_len); /** Fastfind cleanup. It frees the given @a index. * Must be called once per list. diff --git a/src/util/scanner.c b/src/util/scanner.c index d2440967..1545745f 100644 --- a/src/util/scanner.c +++ b/src/util/scanner.c @@ -17,7 +17,8 @@ int map_scanner_string(struct scanner *scanner, - unsigned char *ident, unsigned char *end, int base_type) + const unsigned char *ident, const unsigned char *end, + int base_type) { const struct scanner_string_mapping *mappings = scanner->info->mappings; int length = end - ident; diff --git a/src/util/scanner.h b/src/util/scanner.h index 7949507a..a8846258 100644 --- a/src/util/scanner.h +++ b/src/util/scanner.h @@ -190,7 +190,8 @@ skip_scanner_tokens(struct scanner *scanner, int skipto, int precedence); * @relates scanner */ int map_scanner_string(struct scanner *scanner, - unsigned char *ident, unsigned char *end, int base_type); + const unsigned char *ident, const unsigned char *end, + int base_type); #ifdef DEBUG_SCANNER /** @relates scanner */