Skip to content

Commit

Permalink
Merge pull request #99 from dvlemplgk/random-cookie
Browse files Browse the repository at this point in the history
Randomize session cookie/ID
  • Loading branch information
ch-aurich authored Jan 13, 2017
2 parents 598d1b3 + 739ede6 commit ff500f8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plc/plc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ struct plc plc =
PLC_FLAGS
};

#if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#define RANDOMIZE_COOKIE 1
#endif

#ifdef RANDOMIZE_COOKIE
{
int f;
f = open("/dev/urandom", O_BINARY|O_RDONLY);
if (f >= 0) {
do {
read(f, &plc.cookie, sizeof plc.cookie);
} while (plc.cookie == PLCSESSION || plc.cookie == 0 || plc.cookie == 0xFFFFFFFF);
close(f);
}
}
#endif
#endif


Expand Down

0 comments on commit ff500f8

Please sign in to comment.