Skip to content

Commit e2c97f3

Browse files
flichtenheldcron2
authored andcommitted
multi: Fix type handling for hashes, mostly inotify_watchers
Change-Id: Idede28c850def5e3b4a17dcbd0a5771f15cfc668 Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1312 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg35072.html Signed-off-by: Gert Doering <[email protected]>
1 parent 310c6b9 commit e2c97f3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/openvpn/multi.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static uint32_t
257257
*/
258258
int_hash_function(const void *key, uint32_t iv)
259259
{
260-
return (unsigned long)key;
260+
return (uint32_t)(uintptr_t)key;
261261
}
262262

263263
static bool
@@ -295,22 +295,23 @@ multi_init(struct context *t)
295295
* to determine which client sent an incoming packet
296296
* which is seen on the TCP/UDP socket.
297297
*/
298-
m->hash = hash_init(t->options.real_hash_size, get_random(), mroute_addr_hash_function,
299-
mroute_addr_compare_function);
298+
m->hash = hash_init(t->options.real_hash_size, (uint32_t)get_random(),
299+
mroute_addr_hash_function, mroute_addr_compare_function);
300300

301301
/*
302302
* Virtual address hash table. Used to determine
303303
* which client to route a packet to.
304304
*/
305-
m->vhash = hash_init(t->options.virtual_hash_size, get_random(), mroute_addr_hash_function,
306-
mroute_addr_compare_function);
305+
m->vhash = hash_init(t->options.virtual_hash_size, (uint32_t)get_random(),
306+
mroute_addr_hash_function, mroute_addr_compare_function);
307307

308308
/*
309309
* This hash table is a clone of m->hash but with a
310310
* bucket size of one so that it can be used
311311
* for fast iteration through the list.
312312
*/
313-
m->iter = hash_init(1, get_random(), mroute_addr_hash_function, mroute_addr_compare_function);
313+
m->iter = hash_init(1, (uint32_t)get_random(), mroute_addr_hash_function,
314+
mroute_addr_compare_function);
314315

315316
#ifdef ENABLE_MANAGEMENT
316317
m->cid_hash = hash_init(t->options.real_hash_size, 0, cid_hash_function, cid_compare_function);
@@ -321,8 +322,8 @@ multi_init(struct context *t)
321322
* Mapping between inotify watch descriptors and
322323
* multi_instances.
323324
*/
324-
m->inotify_watchers =
325-
hash_init(t->options.real_hash_size, get_random(), int_hash_function, int_compare_function);
325+
m->inotify_watchers = hash_init(t->options.real_hash_size, (uint32_t)get_random(),
326+
int_hash_function, int_compare_function);
326327
#endif
327328

328329
/*
@@ -609,7 +610,7 @@ multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool sh
609610
#ifdef ENABLE_ASYNC_PUSH
610611
if (mi->inotify_watch != -1)
611612
{
612-
hash_remove(m->inotify_watchers, (void *)(unsigned long)mi->inotify_watch);
613+
hash_remove(m->inotify_watchers, (void *)(uintptr_t)mi->inotify_watch);
613614
mi->inotify_watch = -1;
614615
}
615616
#endif
@@ -2821,7 +2822,7 @@ multi_process_file_closed(struct multi_context *m, const unsigned int mpp_flags)
28212822
msg(D_MULTI_DEBUG, "MULTI: modified fd %d, mask %d", pevent->wd, pevent->mask);
28222823

28232824
struct multi_instance *mi =
2824-
hash_lookup(m->inotify_watchers, (void *)(unsigned long)pevent->wd);
2825+
hash_lookup(m->inotify_watchers, (void *)(uintptr_t)pevent->wd);
28252826

28262827
if (pevent->mask & IN_CLOSE_WRITE)
28272828
{
@@ -2840,7 +2841,7 @@ multi_process_file_closed(struct multi_context *m, const unsigned int mpp_flags)
28402841
/* this event is _always_ fired when watch is removed or file is deleted */
28412842
if (mi)
28422843
{
2843-
hash_remove(m->inotify_watchers, (void *)(unsigned long)pevent->wd);
2844+
hash_remove(m->inotify_watchers, (void *)(uintptr_t)pevent->wd);
28442845
mi->inotify_watch = -1;
28452846
}
28462847
}
@@ -2978,14 +2979,14 @@ add_inotify_file_watch(struct multi_context *m, struct multi_instance *mi, int i
29782979
const char *file)
29792980
{
29802981
/* watch acf file */
2981-
long watch_descriptor = inotify_add_watch(inotify_fd, file, IN_CLOSE_WRITE | IN_ONESHOT);
2982+
int watch_descriptor = inotify_add_watch(inotify_fd, file, IN_CLOSE_WRITE | IN_ONESHOT);
29822983
if (watch_descriptor >= 0)
29832984
{
29842985
if (mi->inotify_watch != -1)
29852986
{
2986-
hash_remove(m->inotify_watchers, (void *)(unsigned long)mi->inotify_watch);
2987+
hash_remove(m->inotify_watchers, (void *)(uintptr_t)mi->inotify_watch);
29872988
}
2988-
hash_add(m->inotify_watchers, (const uintptr_t *)watch_descriptor, mi, true);
2989+
hash_add(m->inotify_watchers, (void *)(uintptr_t)watch_descriptor, mi, true);
29892990
mi->inotify_watch = watch_descriptor;
29902991
}
29912992
else

0 commit comments

Comments
 (0)