Skip to content

Commit 120cc37

Browse files
committed
fixes compilation warnings and UB for LP32 platforms
* convert pointers via uintptr_t to/from integral types * mix in intermediate 64-bit `len` instead of platform-dependently sized `size_t` * default to compiling with -D_FILE_OFFSET_BITS=64 for consistent sendfile64() usage
1 parent 01f40f5 commit 120cc37

7 files changed

Lines changed: 25 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Change Log
22

3+
**Fix**: fixed some 32 bit compatibility concerns. Credit to Franz Brausse ( @fbrausse ) for the [PR @ boazsegev/facil.io#96](https://github.com/boazsegev/facil.io/pull/96).
4+
35
### v. 0.7.5 (2020-05-18)
46

57
**Security**: backport the 0.8.x HTTP/1.1 parser and it's security updates to the 0.7.x version branch. This fixes a request smuggling attack vector and Transfer Encoding attack vector that were exposed by Sam Sanoop from [the Snyk Security team (snyk.io)](https://snyk.io). The parser was updated to deal with these potential issues.

lib/facil/cli/fio_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct {
5050
#define AVOID_MACRO
5151

5252
#define FIO_CLI_HASH_VAL(s) \
53-
fio_risky_hash((s).data, (s).len, (uint64_t)fio_cli_start)
53+
fio_risky_hash((s).data, (s).len, (uintptr_t)fio_cli_start)
5454

5555
/* *****************************************************************************
5656
CLI Parsing

lib/facil/fio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6371,7 +6371,7 @@ static inline void fio_cluster_inform_root_about_channel(channel_s *ch,
63716371
#endif
63726372
char buf[8] = {0};
63736373
if (ch->match) {
6374-
fio_u2str64(buf, (uint64_t)ch->match);
6374+
fio_u2str64(buf, (uintptr_t)ch->match);
63756375
msg.data = buf;
63766376
msg.len = sizeof(ch->match);
63776377
}

lib/facil/fio.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,8 +2539,9 @@ FIO_FUNC inline uint64_t fio_risky_hash(const void *data_, size_t len,
25392539
uint64_t result = fio_lrot64(v0, 17) + fio_lrot64(v1, 13) +
25402540
fio_lrot64(v2, 47) + fio_lrot64(v3, 57);
25412541

2542-
len ^= (len << 33);
2543-
result += len;
2542+
uint64_t len64 = len;
2543+
len64 ^= (len64 << 33);
2544+
result += len64;
25442545

25452546
result += v0 * RISKY_PRIME_1;
25462547
result ^= fio_lrot64(result, 13);

lib/facil/fiobj/fiobject.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,13 @@ FIO_INLINE uint64_t fiobj_obj2hash(const FIOBJ o) {
554554
if (!FIOBJ_IS_ALLOCATED(o))
555555
return (uint64_t)o;
556556
fio_str_info_s s = fiobj_obj2cstr(o);
557-
return FIO_HASH_FN(s.data, s.len, &fiobj_each2, &fiobj_free_complex_object);
557+
return FIO_HASH_FN(s.data, s.len, (uintptr_t)&fiobj_each2,
558+
(uintptr_t)&fiobj_free_complex_object);
558559
}
559560

560561
FIO_INLINE uint64_t fiobj_hash_string(const void *data, size_t len) {
561-
return FIO_HASH_FN(data, len, &fiobj_each2, &fiobj_free_complex_object);
562+
return FIO_HASH_FN(data, len, (uintptr_t)&fiobj_each2,
563+
(uintptr_t)&fiobj_free_complex_object);
562564
}
563565

564566
/**

lib/facil/redis/redis_engine.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static void redis_on_publish_child(const fio_pubsub_engine_s *eng,
684684
fio_str_s tmp = FIO_STR_INIT;
685685
/* by using fio_str_s, short names are allocated on the stack */
686686
fio_str_info_s tmp_info = fio_str_resize(&tmp, channel.len + 8);
687-
fio_u2str64(tmp_info.data, (uint64_t)eng);
687+
fio_u2str64(tmp_info.data, (uintptr_t)eng);
688688
memcpy(tmp_info.data + 8, channel.data, channel.len);
689689
/* forward publication request to Root */
690690
fio_publish(.filter = -1, .channel = tmp_info, .message = msg,
@@ -701,7 +701,7 @@ Root Publication Handler
701701
static void redis_on_internal_publish(fio_msg_s *msg) {
702702
if (msg->channel.len < 8)
703703
return; /* internal error, unexpected data */
704-
void *en = (void *)fio_str2u64(msg->channel.data);
704+
void *en = (void *)(uintptr_t)fio_str2u64(msg->channel.data);
705705
if (en != msg->udata1)
706706
return; /* should be delivered by a different engine */
707707
/* step after the engine data */
@@ -721,8 +721,8 @@ Sending commands using the Root connection
721721
static void redis_forward_reply(fio_pubsub_engine_s *e, FIOBJ reply,
722722
void *udata) {
723723
uint8_t *data = udata;
724-
fio_pubsub_engine_s *engine = (fio_pubsub_engine_s *)fio_str2u64(data + 0);
725-
void *callback = (void *)fio_str2u64(data + 8);
724+
fio_pubsub_engine_s *engine = (fio_pubsub_engine_s *)(uintptr_t)fio_str2u64(data + 0);
725+
void *callback = (void *)(uintptr_t)fio_str2u64(data + 8);
726726
if (engine != e || !callback) {
727727
FIO_LOG_DEBUG("Redis reply not forwarded (callback: %p)", callback);
728728
return;
@@ -738,7 +738,7 @@ static void redis_forward_reply(fio_pubsub_engine_s *e, FIOBJ reply,
738738
static void redis_on_internal_cmd(fio_msg_s *msg) {
739739
// void*(void *)fio_str2u64(msg->msg.data);
740740
fio_pubsub_engine_s *engine =
741-
(fio_pubsub_engine_s *)fio_str2u64(msg->channel.data + 0);
741+
(fio_pubsub_engine_s *)(uintptr_t)fio_str2u64(msg->channel.data + 0);
742742
if (engine != msg->udata1) {
743743
return;
744744
}
@@ -756,7 +756,7 @@ static void redis_on_internal_cmd(fio_msg_s *msg) {
756756
/* Listens on filter `-10 -getpid()` for incoming reply data */
757757
static void redis_on_internal_reply(fio_msg_s *msg) {
758758
fio_pubsub_engine_s *engine =
759-
(fio_pubsub_engine_s *)fio_str2u64(msg->channel.data + 0);
759+
(fio_pubsub_engine_s *)(uintptr_t)fio_str2u64(msg->channel.data + 0);
760760
if (engine != msg->udata1) {
761761
FIO_LOG_DEBUG("Redis reply not forwarded (engine mismatch: %p != %p)",
762762
(void *)engine, msg->udata1);
@@ -765,8 +765,8 @@ static void redis_on_internal_reply(fio_msg_s *msg) {
765765
FIOBJ reply;
766766
fiobj_json2obj(&reply, msg->msg.data, msg->msg.len);
767767
void (*callback)(fio_pubsub_engine_s *, FIOBJ, void *) = (void (*)(
768-
fio_pubsub_engine_s *, FIOBJ, void *))fio_str2u64(msg->channel.data + 8);
769-
void *udata = (void *)fio_str2u64(msg->channel.data + 16);
768+
fio_pubsub_engine_s *, FIOBJ, void *))(uintptr_t)fio_str2u64(msg->channel.data + 8);
769+
void *udata = (void *)(uintptr_t)fio_str2u64(msg->channel.data + 16);
770770
callback(engine, reply, udata);
771771
fiobj_free(reply);
772772
}
@@ -788,9 +788,9 @@ intptr_t redis_engine_send(fio_pubsub_engine_s *engine, FIOBJ command,
788788
fio_str_s tmp = FIO_STR_INIT;
789789
fio_str_info_s ti = fio_str_resize(&tmp, 28);
790790
/* combine metadata */
791-
fio_u2str64(ti.data + 0, (uint64_t)engine);
792-
fio_u2str64(ti.data + 8, (uint64_t)callback);
793-
fio_u2str64(ti.data + 16, (uint64_t)udata);
791+
fio_u2str64(ti.data + 0, (uintptr_t)engine);
792+
fio_u2str64(ti.data + 8, (uintptr_t)callback);
793+
fio_u2str64(ti.data + 16, (uintptr_t)udata);
794794
fio_u2str32(ti.data + 24, (uint32_t)getpid());
795795
FIOBJ cmd = fiobj2resp_tmp(command);
796796
fio_publish(.filter = -2, .channel = ti, .message = fiobj_obj2cstr(cmd),

makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ INCLUDE= ./
7070
# any preprocessosr defined flags we want, space seperated list (i.e. DEBUG )
7171
FLAGS:=
7272

73+
# we use sendfile64() and off_t
74+
override FLAGS += _FILE_OFFSET_BITS=64
75+
7376
# c compiler
7477
ifndef CC
7578
CC=gcc

0 commit comments

Comments
 (0)