Skip to content

Commit 784c0d6

Browse files
authored
Merge branch 'tinyproxy:master' into master
2 parents 87ea606 + 879bf84 commit 784c0d6

8 files changed

Lines changed: 18 additions & 108 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- run: ./configure
1616
- run: make
1717
- run: make test
18+
- run: cd docs/web ; make
1819
test-macos:
1920
runs-on: macos-latest
2021
steps:

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.2
1+
1.11.3

‎docs/man8/Makefile.am‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ else
2929
@echo "*** pod2man is required to regenerate $(@) ***"; exit 1;
3030
endif
3131

32+
CLEANFILES = \
33+
tinyproxy.txt
34+
3235
MAINTAINERCLEANFILES = \
3336
$(MAN8_FILES:.txt=.8)
3437

3538
EXTRA_DIST = \
36-
$(MAN8_FILES:.txt=.8)
39+
$(MAN8_FILES:.txt=.8) \
40+
tinyproxy.txt.in

‎scripts/version.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GIT_DIR="${SCRIPT_DIR}/../.git"
55

66
if test -d "${GIT_DIR}" ; then
77
if type git >/dev/null 2>&1 ; then
8-
gitstr=$(git describe --match '[0-9]*.[0-9]*.*' 2>/dev/null)
8+
gitstr=$(git describe --tags --match '[0-9]*.[0-9]*.*' 2>/dev/null)
99
if test "x$?" != x0 ; then
1010
sed 's/$/-git/' < VERSION
1111
else

‎src/buffer.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,6 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
241241
bytesin = -1;
242242
} else {
243243
switch (errno) {
244-
#ifdef EWOULDBLOCK
245-
case EWOULDBLOCK:
246-
#else
247-
# ifdef EAGAIN
248-
case EAGAIN:
249-
# endif
250-
#endif
251244
case EINTR:
252245
bytesin = 0;
253246
break;
@@ -295,13 +288,6 @@ ssize_t write_buffer (int fd, struct buffer_s * buffptr)
295288
return bytessent;
296289
} else {
297290
switch (errno) {
298-
#ifdef EWOULDBLOCK
299-
case EWOULDBLOCK:
300-
#else
301-
# ifdef EAGAIN
302-
case EAGAIN:
303-
# endif
304-
#endif
305291
case EINTR:
306292
return 0;
307293
case ENOBUFS:

‎src/reqs.c‎

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,10 @@ static struct request_s *process_request (struct conn_s *connptr,
524524
* server headers can be processed.
525525
* - rjkaes
526526
*/
527-
static int pull_client_data (struct conn_s *connptr, long int length, int iehack)
527+
static int pull_client_data (struct conn_s *connptr, long int length)
528528
{
529529
char *buffer;
530530
ssize_t len;
531-
int ret;
532531

533532
buffer =
534533
(char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length));
@@ -549,43 +548,6 @@ static int pull_client_data (struct conn_s *connptr, long int length, int iehack
549548
length -= len;
550549
} while (length > 0);
551550

552-
if (iehack) {
553-
/*
554-
* BUG FIX: Internet Explorer will leave two bytes (carriage
555-
* return and line feed) at the end of a POST message. These
556-
* need to be eaten for tinyproxy to work correctly.
557-
*/
558-
ret = socket_nonblocking (connptr->client_fd);
559-
if (ret != 0) {
560-
log_message(LOG_ERR, "Failed to set the client socket "
561-
"to non-blocking: %s", strerror(errno));
562-
goto ERROR_EXIT;
563-
}
564-
565-
len = recv (connptr->client_fd, buffer, 2, MSG_PEEK);
566-
567-
ret = socket_blocking (connptr->client_fd);
568-
if (ret != 0) {
569-
log_message(LOG_ERR, "Failed to set the client socket "
570-
"to blocking: %s", strerror(errno));
571-
goto ERROR_EXIT;
572-
}
573-
574-
if (len < 0 && errno != EAGAIN)
575-
goto ERROR_EXIT;
576-
577-
if ((len == 2) && CHECK_CRLF (buffer, len)) {
578-
ssize_t bytes_read;
579-
580-
bytes_read = read (connptr->client_fd, buffer, 2);
581-
if (bytes_read == -1) {
582-
log_message
583-
(LOG_WARNING,
584-
"Could not read two bytes from POST message");
585-
}
586-
}
587-
}
588-
589551
safefree (buffer);
590552
return 0;
591553

@@ -613,8 +575,10 @@ static int pull_client_data_chunked (struct conn_s *connptr) {
613575
}
614576

615577
chunklen = strtol (buffer, (char**)0, 16);
578+
/* prevent negative or huge values causing overflow */
579+
if (chunklen < 0 || chunklen > 0x0fffffff) goto ERROR_EXIT;
616580

617-
if (pull_client_data (connptr, chunklen+2, 0) < 0)
581+
if (pull_client_data (connptr, chunklen+2) < 0)
618582
goto ERROR_EXIT;
619583

620584
if(!chunklen) break;
@@ -848,7 +812,7 @@ static int is_chunked_transfer (pseudomap *hashofheaders)
848812
{
849813
char *data;
850814
data = pseudomap_find (hashofheaders, "transfer-encoding");
851-
return data ? !strcmp (data, "chunked") : 0;
815+
return data ? !strcasecmp (data, "chunked") : 0;
852816
}
853817

854818
/*
@@ -1007,7 +971,7 @@ process_client_headers (struct conn_s *connptr, pseudomap *hashofheaders)
1007971
PULL_CLIENT_DATA:
1008972
if (connptr->content_length.client > 0) {
1009973
ret = pull_client_data (connptr,
1010-
connptr->content_length.client, 1);
974+
connptr->content_length.client);
1011975
} else if (connptr->content_length.client == -2)
1012976
ret = pull_client_data_chunked (connptr);
1013977

@@ -1194,8 +1158,8 @@ static int process_server_headers (struct conn_s *connptr)
11941158
}
11951159

11961160
/*
1197-
* Switch the sockets into nonblocking mode and begin relaying the bytes
1198-
* between the two connections. We continue to use the buffering code
1161+
* Begin relaying the bytes between the two connections.
1162+
* We continue to use the buffering code
11991163
* since we want to be able to buffer a certain amount for slower
12001164
* connections (as this was the reason why I originally modified
12011165
* tinyproxy oh so long ago...)
@@ -1268,14 +1232,6 @@ static void relay_connection (struct conn_s *connptr)
12681232
/*
12691233
* Try to send any remaining data to the server if we can.
12701234
*/
1271-
ret = socket_blocking (connptr->server_fd);
1272-
if (ret != 0) {
1273-
log_message(LOG_ERR,
1274-
"Failed to set server socket to blocking: %s",
1275-
strerror(errno));
1276-
return;
1277-
}
1278-
12791235
while (buffer_size (connptr->cbuffer) > 0) {
12801236
if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0)
12811237
break;
@@ -1572,16 +1528,9 @@ static void auth_error(struct conn_s *connptr, int code) {
15721528
}
15731529

15741530
/*
1575-
* This is the main drive for each connection. As you can tell, for the
1576-
* first few steps we are using a blocking socket. If you remember the
1577-
* older tinyproxy code, this use to be a very confusing state machine.
1578-
* Well, no more! :) The sockets are only switched into nonblocking mode
1579-
* when we start the relay portion. This makes most of the original
1580-
* tinyproxy code, which was confusing, redundant. Hail progress.
1581-
* - rjkaes
1582-
1531+
* This is the main drive for each connection.
15831532
* this function is called directly from child_thread() with the newly
1584-
* received fd from accept().
1533+
* received fd from accept().
15851534
*/
15861535
void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
15871536
{

‎src/sock.c‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -222,33 +222,6 @@ int opensock (const char *host, int port, const char *bind_to)
222222
return sockfd;
223223
}
224224

225-
/*
226-
* Set the socket to non blocking -rjkaes
227-
*/
228-
int socket_nonblocking (int sock)
229-
{
230-
int flags;
231-
232-
assert (sock >= 0);
233-
234-
flags = fcntl (sock, F_GETFL, 0);
235-
return fcntl (sock, F_SETFL, flags | O_NONBLOCK);
236-
}
237-
238-
/*
239-
* Set the socket to blocking -rjkaes
240-
*/
241-
int socket_blocking (int sock)
242-
{
243-
int flags;
244-
245-
assert (sock >= 0);
246-
247-
flags = fcntl (sock, F_GETFL, 0);
248-
return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK);
249-
}
250-
251-
252225
/**
253226
* Try to listen on one socket based on the addrinfo
254227
* as returned from getaddrinfo.

‎src/sock.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ union sockaddr_union {
5353
extern int opensock (const char *host, int port, const char *bind_to);
5454
extern int listen_sock (const char *addr, uint16_t port, sblist* listen_fds);
5555

56-
extern int socket_nonblocking (int sock);
57-
extern int socket_blocking (int sock);
58-
5956
extern void set_socket_timeout(int fd);
6057

6158
extern int getsock_ip (int fd, char *ipaddr);

0 commit comments

Comments
 (0)