Skip to content

Commit

Permalink
ws: fix compile error on centos 7 - very old compiler (libevent#1359)
Browse files Browse the repository at this point in the history
* http: fix typo

* ws: fix comile error

On CentOS:

  CC       ws.lo
ws.c: In function 'get_ws_frame':
ws.c:244:3: error: 'for' loop initial declarations are only allowed in C99 mode
   for (int i = 0; i < payload_len; i++) {
   ^
ws.c:244:3: note: use option -std=c99 or -std=gnu99 to compile your code
  • Loading branch information
yogo1212 authored Oct 23, 2022
1 parent f04a70f commit 3ec3b46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion http.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ evhttp_connection_incoming_fail(struct evhttp_request *req,
* case may happen when a browser keeps a persistent
* connection open and we timeout on the read. when
* the request is still being used for sending, we
* need to disassociated it from the connection here.
* need to disassociate it from the connection here.
*/
if (!req->userdone) {
/* remove it so that it will not be freed */
Expand Down
6 changes: 4 additions & 2 deletions test/regress_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ receive_ws_msg(struct evbuffer *buf, size_t *out_len, unsigned *options)
const unsigned char *mask_key;
char *out_buf = NULL;
size_t data_len = evbuffer_get_length(buf);
size_t i;

data = evbuffer_pullup(buf, data_len);

Expand Down Expand Up @@ -177,7 +178,7 @@ receive_ws_msg(struct evbuffer *buf, size_t *out_len, unsigned *options)
return NULL;

mask_key = data + header_len - 4;
for (size_t i = 0; mask && i < payload_len; i++)
for (i = 0; mask && i < payload_len; i++)
data[header_len + i] ^= mask_key[i % 4];

*out_len = payload_len;
Expand Down Expand Up @@ -205,6 +206,7 @@ send_ws_msg(struct evbuffer *buf, const char *msg, bool final)
uint8_t a = 0, b = 0, c = 0, d = 0;
uint8_t mask_key[4] = {1, 2, 3, 4}; /* should be random */
uint8_t m;
size_t i;

if (final)
a |= 1 << 7; /* fin */
Expand Down Expand Up @@ -233,7 +235,7 @@ send_ws_msg(struct evbuffer *buf, const char *msg, bool final)

evbuffer_add(buf, &mask_key, 4);

for (size_t i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
m = msg[i] ^ mask_key[i % 4];
evbuffer_add(buf, &m, 1);
}
Expand Down
3 changes: 2 additions & 1 deletion ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ get_ws_frame(unsigned char *in_buffer, int buf_len, unsigned char **payload_ptr,
*/
if (masked) {
unsigned char *c;
int i;

mask = *((unsigned int *)(in_buffer + pos));
pos += 4;

/* unmask data */
c = in_buffer + pos;
for (int i = 0; i < payload_len; i++) {
for (i = 0; i < payload_len; i++) {
c[i] = c[i] ^ ((unsigned char *)(&mask))[i % 4];
}
}
Expand Down

0 comments on commit 3ec3b46

Please sign in to comment.