diff options
author | Mattias Andrée <m@maandree.se> | 2024-10-05 23:23:17 +0200 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2024-10-05 23:23:17 +0200 |
commit | 98a8ac8498974e499fc129878ab05b9a7bf8ba30 (patch) | |
tree | 2914967687516632a93da9af59818f22d3120861 /src/libmdsclient | |
parent | Update e-mail (diff) | |
download | mds-master.tar.gz mds-master.tar.bz2 mds-master.tar.xz |
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/libmdsclient')
-rw-r--r-- | src/libmdsclient/address.c | 2 | ||||
-rw-r--r-- | src/libmdsclient/address.h | 2 | ||||
-rw-r--r-- | src/libmdsclient/comm.c | 2 | ||||
-rw-r--r-- | src/libmdsclient/comm.h | 2 | ||||
-rw-r--r-- | src/libmdsclient/inbound.c | 82 | ||||
-rw-r--r-- | src/libmdsclient/inbound.h | 2 | ||||
-rw-r--r-- | src/libmdsclient/proto-util.c | 2 | ||||
-rw-r--r-- | src/libmdsclient/proto-util.h | 2 |
8 files changed, 11 insertions, 85 deletions
diff --git a/src/libmdsclient/address.c b/src/libmdsclient/address.c index b41c9c4..2aac894 100644 --- a/src/libmdsclient/address.c +++ b/src/libmdsclient/address.c @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libmdsclient/address.h b/src/libmdsclient/address.h index e710ba6..3380e9f 100644 --- a/src/libmdsclient/address.h +++ b/src/libmdsclient/address.h @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libmdsclient/comm.c b/src/libmdsclient/comm.c index dd0a38f..7c0712a 100644 --- a/src/libmdsclient/comm.c +++ b/src/libmdsclient/comm.c @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libmdsclient/comm.h b/src/libmdsclient/comm.h index 9df1d41..3d25a05 100644 --- a/src/libmdsclient/comm.h +++ b/src/libmdsclient/comm.h @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libmdsclient/inbound.c b/src/libmdsclient/inbound.c index 85b8b34..5a8e868 100644 --- a/src/libmdsclient/inbound.c +++ b/src/libmdsclient/inbound.c @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,8 @@ #include <stdio.h> #include <assert.h> +#include <libsimple.h> + #define try(INSTRUCTION) do { if ((r = INSTRUCTION) < 0) return r; } while (0) #define static_strlen(str) (sizeof(str) / sizeof(char) - 1) @@ -124,82 +126,6 @@ repoll: /** - * Check whether a NUL-terminated string is encoded in UTF-8 - * - * @param string The string - * @param allow_modified_nul Whether Modified UTF-8 is allowed, which allows a two-byte encoding for NUL - * @return Zero if good, -1 on encoding error - */ -static int __attribute__((nonnull, warn_unused_result)) /* Cannibalised from <libmdsserver/util.h>. */ -verify_utf8(const char *string, int allow_modified_nul) -{ - static long BYTES_TO_MIN_BITS[] = {0, 0, 8, 12, 17, 22, 37}; - static long BYTES_TO_MAX_BITS[] = {0, 7, 11, 16, 21, 26, 31}; - long bytes = 0, read_bytes = 0, bits = 0, c, character; - - /* min bits max bits - 0....... 0 7 - 110..... 10...... 8 11 - 1110.... 10...... 10...... 12 16 - 11110... 10...... 10...... 10...... 17 21 - 111110.. 10...... 10...... 10...... 10...... 22 26 - 1111110. 10...... 10...... 10...... 10...... 10...... 27 31 - */ - - while ((c = (long)(*string++))) { - if (!read_bytes) { - /* First byte of the character. */ - - if (!(c & 0x80)) - /* Single-byte character. */ - continue; - - if ((c & 0xC0) == 0x80) - /* Single-byte character marked as multibyte, or - a non-first byte in a multibyte character. */ - return -1; - - /* Multibyte character. */ - while ((c & 0x80)) - bytes++, c <<= 1; - read_bytes = 1; - character = c & 0x7F; - if (bytes > 6) - /* 31-bit characters can be encoded with 6-bytes, - and UTF-8 does not cover higher code points. */ - return -1; - } else { - /* Not first byte of the character. */ - - if ((c & 0xC0) != 0x80) - /* Beginning of new character before a - multibyte character has ended. */ - return -1; - - character = (character << 6) | (c & 0x7F); - - if (++read_bytes < bytes) - /* Not at last byte yet. */ - continue; - - /* Check that the character is not unnecessarily long. */ - while (character) - character >>= 1, bits++; - bits = ((bits == 0) && (bytes == 2) && allow_modified_nul) ? 8 : bits; - if ((bits < BYTES_TO_MIN_BITS[bytes]) || (BYTES_TO_MAX_BITS[bytes] < bits)) - return -1; - - read_bytes = bytes = bits = 0; - } - } - - /* Make sure we did not stop at the middle of a multibyte character. */ - return read_bytes == 0 ? 0 : -1; -} - - - -/** * Extend the header list's allocation * * @param this The message @@ -313,7 +239,7 @@ validate_header(const char *header, size_t length) { char *p = memchr(header, ':', length * sizeof(char)); - if (verify_utf8(header, 0) < 0) + if (!isutf8(header, 0)) /* Either the string is not UTF-8, or your are under an UTF-8 attack, let's just call this unrecoverable because the client will not correct. */ return -2; diff --git a/src/libmdsclient/inbound.h b/src/libmdsclient/inbound.h index 0342a8d..33d5a82 100644 --- a/src/libmdsclient/inbound.h +++ b/src/libmdsclient/inbound.h @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libmdsclient/proto-util.c b/src/libmdsclient/proto-util.c index 4671a0c..8752e46 100644 --- a/src/libmdsclient/proto-util.c +++ b/src/libmdsclient/proto-util.c @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libmdsclient/proto-util.h b/src/libmdsclient/proto-util.h index 0e8fbf9..d1d68d9 100644 --- a/src/libmdsclient/proto-util.h +++ b/src/libmdsclient/proto-util.h @@ -1,6 +1,6 @@ /** * mds — A micro-display server - * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (maandree@kth.se) + * Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by |