1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-12-22 04:02:04 +03:00
Commit Graph

2380 Commits

Author SHA1 Message Date
Matt Clarkson
066850c251 Attempt to sanitize the implicit casts in mg_read
There are implicit casts between size_t and int here that can be solved
multiple ways. This attempts to keep values as close to their declared
types.
2015-05-21 21:07:39 +02:00
Matt Clarkson
3e1f9569df Make the length cast explicit
This is could be a bug if the len is greater than INT64_MAX, but the
code doesn't seem to care about this, so adding the explicit cast
to remove the compiler warning.
2015-05-21 21:06:30 +02:00
Matt Clarkson
baa3ed606e Size should be size_t
This removes an implicit conversion when calling vsnprintf
2015-05-21 21:05:57 +02:00
Matt Clarkson
e6b26a05ee Cast the allocation length to size_t
It is safe to cast up the length integer to size_t here because
we have already checked that it is greater than zero.
2015-05-21 21:05:07 +02:00
Matt Clarkson
16adaf09f5 Correctly cast the pointer arithmetic
memchr accepts the count as a size_t type.
2015-05-21 21:03:53 +02:00
Matt Clarkson
4597ea02fa Directory entries now unsigned
There is never a situation where a directory can have a negative amount of
entries
2015-05-21 21:03:04 +02:00
Matt Clarkson
c395c16b75 The count of environment vars is unsigned
This is more sematically correct, there will never be a negative amount of
environment variables. It also fixes up some implicit casting errors.
2015-05-21 21:02:43 +02:00
Matt Clarkson
4a94c1fb6d Add explicit casts to size_t in mg_upload
These casts convert the result of signed arithmetic into the correct
size_t type that the function accept. This doesn't alter any of the
logic in the function just tells the compiler that we know what we are
doing with respect to the conversions. This patch highlights that more
thorough reviews of the overflow of the arithmetic are needed before
assuming conversion to unsigned is acceptable.
2015-05-21 21:02:10 +02:00
Matt Clarkson
53c7cced39 Make read length explicitly size_t
There is a implicit cast from an integer to size_t for the length
parameter to mg_read. This patch makes that cast implicit by casting
the len to size_t. This doesn't check if the len is negative but it
shouldn't need to because if mg_read is given a huge number to read
(because the calculation wrapped around) it will just read until the
end of the socket data.
2015-05-21 21:01:35 +02:00
Matt Clarkson
f630d3ff9d Implicit conversion cast when invalidating port
This can easily be solved by splitting the assignments onto two
seperate lines.
2015-05-21 21:00:24 +02:00
Matt Clarkson
a23bcd4ab7 Clamp the return value of CRYPTO_num_locks
This avoids an implicit conversion to size_t from an int and does
the multiplication in the size_t type.
2015-05-21 20:59:52 +02:00
Matt Clarkson
f5eecb5988 Only do a memmove when size is positive
The previous code would do a unbounded memmove if the discard_len was
greater than the data_len. This patch puts a check in place to make sure
we do not do huge memory moves due to an integer wrapping around into
the unsigned size_t type. This occurs due to an implicit cast from the
subtraction
2015-05-21 20:59:14 +02:00
Matt Clarkson
75742921cc Compare queue size as signed
When comparing the queue size it must be an integer otherwise there
is a implicit conversion to an integer. The local QUEUE_SIZE macro
allows for a simple and concise way to do this.
2015-05-21 20:58:47 +02:00
Matt Clarkson
5c0c33c5ab Worker thread count is unsigned
There should never be a negative amount of worker threads. Sematically this
makes sense and solves a lot of casting issues.
2015-05-21 20:58:14 +02:00
Matt Clarkson
56dca7506a Number of listening sockets now unsigned
We should never have a negative amount of listening sockets so there
is no need to have the number as a signed integer. This solves a lot
of signed conversion issues and is more semantically correct.
2015-05-21 20:57:33 +02:00
Matt Clarkson
8987bcd994 The result of pointer arithmetic is ptrdiff_t
When subtracting the string lengths the result is a ptrdiff_t which
is signed. When we assign that to the vec->len field we do an
implicit conversion to unsigned. This makes that conversion explicit.
2015-05-21 20:55:58 +02:00
Matt Clarkson
b6cbc926ce The result of pointer arithmetic is ptrdiff_t
When subtracting the string lengths the result is a ptrdiff_t which
is signed. When we assign that to the vec->len field we do an
implicit conversion to unsigned. This makes that conversion explicit.
2015-05-21 20:55:04 +02:00
Matt Clarkson
b283aeff03 Use size_t when checking string lengths
strlen returns size_t so we should use the correct types
2015-05-21 20:53:21 +02:00
Matt Clarkson
8315399d76 Provide replacement for DEBUG_TRACE
When DEBUG_TRACE isn't used it removes the functions from the body
of the code. This can lead to subtle bugs though as the following
will result in unexpected behaviour:

    if (whatever)
      DEBUG_TRACE(trace some stuff here)
    foobar()

When DEBUG_TRACE is enabled it will be called when `whatever` is true.
However, when DEBUG_TRACE is removed the `foobar()` function call is
then absorbed into the conditional.
2015-05-21 20:52:02 +02:00
Matt Clarkson
82b5698e43 static_assert is available in C++11 and C11
Compliant c++ compilers define __cplusplus to a long integer depending on
the version of C++:

  * C++ pre-C++98 - `1`
  * C++98 - `19971L`
  * C++11 - `201103L`
  * C++14 - `201402L`

Any compiler that states that it is C++11 compilant should have
static_assert available

C compilers define __STDC_VERSION__ to:

  * C89 - `1` (but not always defined)
  * C94 - `199409L`
  * C99 - `199901L`
  * C11 - `201112L`

C11 has the _Static_assert keyword
2015-05-21 20:51:08 +02:00
Matt Clarkson
ceecf6fb72 Fix up extra semi-colon in mg_static_assert
The replacement for static_assert results in double semi-colons for
compilers that do not support static_assert
2015-05-21 20:49:46 +02:00
bel
448563dc21 Resolve merge conflicts for #129 2015-05-21 20:45:49 +02:00
bel
ffa9368437 Avoid warning #128 2015-05-21 19:31:30 +02:00
bel
a1c09b8186 Only use one command in a line in the unit test 2015-05-20 20:07:18 +02:00
Dialga
058ec79027 Merge remote-tracking branch 'upstream/master' 2015-05-20 14:19:56 +12:00
bel
1549ac7905 Minor cleanup related to #126 2015-05-19 22:02:48 +02:00
bel2125
edce697f6c Merge pull request #126 from kalphamon/patch-1
In a "bad request" reply, do not send back the content of the request in the reply
2015-05-19 21:55:04 +02:00
bel
75173d5eee Remove include of "solarisfixes.h"
According to tests performed by @hansipie, an include of "solarisfixes.h" is not
required. See discussion:
97fb2a34e0 (commitcomment-11235602)
2015-05-18 22:33:43 +02:00
kalphamon
aba522b352 Minor change to civetweb.c
When reporting an error if parse_http_message were to fail, sending back user input as is to the client poses a security risk to browsers. I propose removing the string in the error reporting.
2015-05-18 12:30:24 -07:00
bel
b66d5cdfaf Fix static_assert replacement for gcc 2015-05-17 23:20:52 +02:00
bel
c057e1be96 Reformat remaining multiline comments 2015-05-17 23:09:05 +02:00
bel
98c49f8a5a Fine tuning of source code autoformat 2015-05-17 22:03:43 +02:00
bel
82ee8b5cca Move static_assert from inside a function to the definition 2015-05-17 21:49:07 +02:00
bel
11702ede7c Replacement for static_assert 2015-05-17 21:32:59 +02:00
bel
68efcaa79e Format multiline comments 2015-05-17 12:59:35 +02:00
bel
9b4095f54d All macros should be enclosed by () 2015-05-17 12:58:39 +02:00
bel
6ce8b4e92c Set autoformat options and autoformat all source files 2015-05-17 01:30:21 +02:00
bel
53a18aecf1 Autoformat all source files using clang-format 2015-05-17 00:48:11 +02:00
bel
aac1b32c2a Autoformat source using clang-format 2015-05-17 00:45:34 +02:00
bel
c2fbee32d9 Autoformat indent after format suffered from merges 2015-05-16 23:25:28 +02:00
bel
f95f44d7fe Merge branch 'hansipie-cherrypick' 2015-05-16 23:15:13 +02:00
bel
9b12191aa3 Resolve merge conflicts of #124 2015-05-16 23:14:19 +02:00
hansipie
e71e2d7a9c inline under Solaris
Remove my correction for "__inline" unknown under Solaris. New one
imported from another branch.

Conflicts:
	src/civetweb.c
2015-05-16 22:45:41 +02:00
hansipie
072b153431 Source check validation
Mistakes reported by check source tools :
- asserts replacement
- check null value of functions input
- hazardous pointer's value

Conflicts:
	src/civetweb.c
2015-05-16 22:44:11 +02:00
bel
8fdb21e534 Remove setjmp include
setjmp/longjmp are not used, so this include is not required
2015-05-15 00:35:26 +02:00
bel
094b2fde7c Call Lua using the official interface in main 2015-05-15 00:35:23 +02:00
Dialga
9e77ac2c88 Merge remote-tracking branch 'upstream/master'
Updates from master
2015-05-15 09:41:33 +12:00
Dialga
d50cb5b617 Fix makefile for cross compilation 2015-05-15 09:40:23 +12:00
bel2125
8fcb5b4ab2 Merge pull request #125 from sunsetbrew/master
Fixed using CGI interpreters with spaces in the path.
2015-05-14 22:04:07 +02:00
Thomas Davis
30aa23f361 Fixed using CGI iterpreters with spaces in the path. 2015-05-14 12:43:54 -04:00