Git Product home page Git Product logo

libhttp's People

Contributors

arnout avatar bel2125 avatar bgreat avatar c-mauderer avatar cpq avatar dalgaaf avatar danieloaks avatar dialga avatar fremouw avatar grenclave avatar hansipie avatar harikamath avatar jd-boyd avatar jmc- avatar jmucchiello avatar joelgallant avatar kainjow avatar keithel avatar kkyzivat-mosaic avatar lammertb avatar mattyclarkson avatar mgralka avatar nihildeb avatar oldmancoyote avatar phillab avatar pijyoi avatar thewaterymoon avatar tzimmofsecure avatar xtne6f avatar yehudasa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libhttp's Issues

Some connection items are bools

The fields must_close, in_error_handler and internal_error seem to be booleans and it would be better to declare them as such.

httplib_connect_client_impl is not thread safe

This function uses a fake ctx structure which is static and returned in the connection if this function returns. So technically there can only run one client connection at the time.

XX_httplib_push_all / push type mismatch

The function XX_httplib_push_all takes a len parameter of type int64_t, whereas the function push() takes an int parameter which is less than 64 bits on many architectures. A cast hides the potential danger of this.

Suspicious free in XX_httplib_websockets_client_thread

At the end of the function cdata is freed, but cdata is just a pointer to some externally allocated memory. This is suspicious and the function call may either be legitimate, but in that case also all children of the cdata structure should be examined, or it is a bogus call and should be removed entirely from the code base.

System and context initialization mixed up

A number of system initialization calls are currently in httplib_start(). This makes it impossible to call the function httplib_start() multiple times for multiple contexts to run independent servers with independent functionality, different DOCUMENT_ROOT etc. One-time system initialization functions must be moved to httplib_system_init() to make it possible to start multiple independent contexts.

Please actually update the docs

As I spent hours trying to get this to compile, I realized that the documentation differs so much from the actual thing that I need to do just to make it work.

ctx->config fields sometimes used without NULL check

In some places in the software ctx->config members are first tested against NULL and only afterwards used but in other places these members are used directly without check. This may be cause for memory faults.

build failure (Linux/Debian/Sid/gcc-8) commit bd926d18df4ec7182b3fa1

The commit bd926d1 (the latest one today nov.18th 2018 on master) fails to build:


cc -c  -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wformat-security -Winit-self -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -Wredundant-decls -Werror -O3 -funsigned-char -Iinclude/ -DUSE_STACK_SIZE=102400 -oobj/httplib_ssl_get_client_cert_info.o src/httplib_ssl_get_client_cert_info.c
src/httplib_ssl_get_client_cert_info.c: In function ‘XX_httplib_ssl_get_client_cert_info’:
src/httplib_ssl_get_client_cert_info.c:101:15: error: cast between incompatible function types from ‘int (*)(X509 *, unsigned char **)’ {aka ‘int (*)(struct x509 *, unsigned char **)’} to ‘int (*)(void)’ [-Werror=cast-function-type]
  ASN1_digest( (int (*)(void))i2d_X509, digest, (char *)cert, buf, &ulen );
               ^
cc1: all warnings being treated as errors
make: *** [Makefile:148: obj/httplib_ssl_get_client_cert_info.o] Error 1

This is on Linux/x86-64/Debian/Sid the GCC compiler is gcc version 8.2.0 (Debian 8.2.0-9). The GNU libc is Debian GLIBC 2.27-8. The kernel is Linux version 4.18.0-2-rt-amd64

Wrong AND used in httplib_start()

In httplib_start() a local variable ok is used to check a number of return codes. The values to this variable are assigned with the &= operator. Unfortunately this is a bit wise AND operator while a boolean AND (&&) should have been used. This can give strange effects, for example:

1 && 2 is TRUE because both values are non-zero
1 & 2 is FALSE because the values do not share any bits

This is a highly dangerous construct and a typical example of knowing just enough to be dangerous.

XX_httplib_read_websocket() asserts in production code

Having asserts in production code is plain wrong. If rare conditions are not met, functions should stop gracefully and inform the higher calling party about the problem.

Imagine that Linux or Windows had asserts in their code.

Ohh yes, Windows have their BOD......

No error handling in static push() function

The block for errno handling in the static push function is very very empty. This is called nice weather code. As long as everything goes fine everybody thinks the program is working. But when it starts raining the problems start.

Port number should be uint16_t

Changing port number to uint16_t would reduce the number of checks and conversions significantly. It should be checked first however if in some border case negative or large numbers are assigned to the port number for specific undocumented purposes.

XX_httplib_worker_thread() frees memory it doesn't own

The function XX_httplib_worker_thread() frees memory which was passed to it as parameter and which it doesn't own. This assumes that the pointer is valid and was allocated before and not static, and that the memory structure is not complex with other memory blocks to be freed. This may be legitimate or not, but should be investigated.

CGI behavior if DOCUMENT_ROOT is NULL

When preparing the CGI environment, it is possible that the config option DOCUMENT_ROOT is NULL. Security issues may arise if no document root is set in the CGI call. This situation has to be carefully analyzed.

IPv6 doesn't do throttling

The throttle functionality is triggered based on a uint32_t variable. Therefore it doesn't work with IPv6.

Config options have two independent indexes

Config options are both recognized by their name, and by constants defined in an enum. This is error prone because both get easily out of sync. This should be changed to lookup by name only.

IPv6 support must always be compiled

In 2016, IPv6 is no longer an afterthought but a necessity. Apple tests all their iPhone apps in a IPv6-only environment for example. Therefore IPv6 support should always be compiled in and switched on or off with runtime options rather than compile time options.

Why?

I may be off base here, but whenever I find a new library I try to discern the motivation for creating it. Why are you making this library? What does it address that other libraries don't? Not just the technologies, what are the philosophical differences you have with other libraries that led to you creating this library as opposed to contributing to another that you derived from?

By the way, I do love it. I just want other people to be able to enjoy it without prejudice.

Not building on GCC 7.2 (Unused variable)

libhttp git:(master) make
....stuff
src/httplib_error_string.c: In function ‘httplib_error_string’:
src/httplib_error_string.c:170:2: error: ignoring return value of ‘strerror_r’, declared with attribute 
warn_unused_result [-Werror=unused-result]
  strerror_r( error_code, buf, buf_len );
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Static variable blocks multithreading in httplib_connect_websocket_client

In httplib_connect_websocket_client() a variable handshake_req is used which is declared static. The contents of this variable changes with every call depending on a parameter. This is not thread safe because the value of this variable may change unexpectedly and there also doesn't seem to be a reason why this should be a static variable.

Has to be fixed after further investigation.

Benchmarks?

Just curious about the performance of this. I write a lot of code in Go and there is a bunch of http packages and all of them provide benchmarks mostly to let others know that when choosing an http package which one best suites their needs.

So my thought is if you provided some benchmarks that might help people decide if its worth this over others that exist out there.

Does not compile with MinGW

The makefile defaults to MSVC tools when Windows is detected, maybe there is a way to make it detect if its running in MSYS2 and switch to GCC automatically?

CGI behavior if AUTHENTICATION_DOMAIN is NULL

When preparing a CGI environment, AUTHENTICATION_DOMAIN can be NULL. For security reasons it must be carefully analyzed what the implications are if no server value is passed to the CGI script.

Does libhttp support FreeRTOS+LWIP ?

Hi Lammertb,

I just want to know if libhttp supports FreeRTOS + LWIP environment.
I am trying to make a http server on Zynq 7000 SoC chip and
am using FreeRTOS with LWIP.
Would you mind telling me how to compile and run on FreeRTOS ?
Thank you in advance,

kevin

httplib_free_context() frees static strings

In httplib_free_context() runs a for loop over all ctx->config options to free them. This part already has a MSVC warning 6001 disabled. This looks fishy because it is not guaranteed that all memory blocks in the config block have been allocated from the heap before.

SSI code loads files without DOCUMENT_ROOT

SSI code can load files without a DOCUMENT_ROOT set. This more or less negates the idea of the NO_FILES option, because you can still serve files through SSI files. The NO_FILES option therefore only seems to be effective for static furniture like images etc. HTML can still be servered through .shtml files.

This is confusing and needs a proper solution.

Windows socket errors are not reported properly.

Windows error codes are retrieved with GetLastError(), but the human readable text for these error codes is retrieved with the Posix type strerror() which assumes errno error codes. The error codes do not match so in practice you won't see any human readable errors in a Windows installation.

This must be fixed.

WinCE version of localtime not thread safe

The Windows CE implementation of localtime() uses an array to store the return values of the function. This array can store the same amount of values as LibHTTP starts worker threads. If the main application however also uses the LibHTTP provided localtime function in additional threads created outside of the scope of LibHTTP, this may cause overwriting the values belonging to other threads.

Thread local storage should be used in this function, or better, all calls to localtime() should be replaced to calls to localtime_s() which uses storage provided by the calling thread.

The same problem is also existing in the Windows CE implementation for gmtime() which is the UTC equivalent of localtime().

Error building libhttp

Hello,
I am encountering an error when trying to build. This appears to be a case of warning treated as error. Do the build instructions still hold good? (I tried make build and it gave me an error)

Issue 1:
Build issue on ubuntu

$ uname -a
Linux ubuntu 4.13.0-16-generic #19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

$ make
cc -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wformat-security -Winit-self -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -Wredundant-decls -Werror -O3 -funsigned-char -Iinclude/ -DUSE_STACK_SIZE=102400 -oobj/httplib_error_string.o src/httplib_error_string.c
src/httplib_error_string.c: In function ‘httplib_error_string’:
src/httplib_error_string.c:170:2: error: ignoring return value of ‘strerror_r’, declared with attribute warn_unused_result [-Werror=unused-result]
strerror_r( error_code, buf, buf_len );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:148: recipe for target 'obj/httplib_error_string.o' failed
make: *** [obj/httplib_error_string.o] Error 1

Issue-2:
on MAC the build failed with a different error:

$ make
cc -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wformat-security -Winit-self -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -Wredundant-decls -Werror -O3 -funsigned-char -Iinclude/ -DUSE_STACK_SIZE=102400 -oobj/extern_sha1.o src/extern_sha1.c
In file included from src/extern_sha1.c:28:
src/httplib_main.h:130:9: error: 'CLOCK_MONOTONIC' macro redefined [-Werror,-Wmacro-redefined]
#define CLOCK_MONOTONIC (1)
^
/usr/include/time.h:156:9: note: previous definition is here
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
^
In file included from src/extern_sha1.c:28:
src/httplib_main.h:131:9: error: 'CLOCK_REALTIME' macro redefined [-Werror,-Wmacro-redefined]
#define CLOCK_REALTIME (2)
^
/usr/include/time.h:154:9: note: previous definition is here
#define CLOCK_REALTIME _CLOCK_REALTIME
^
2 errors generated.
make: *** [obj/extern_sha1.o] Error 1

$ make -f Makefile.osx
cc -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wformat-security -Winit-self -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -Wredundant-decls -Werror -O3 -funsigned-char -Iinclude/ -DUSE_STACK_SIZE=102400 -oobj/extern_sha1.o src/extern_sha1.c
In file included from src/extern_sha1.c:28:
src/httplib_main.h:130:9: error: 'CLOCK_MONOTONIC' macro redefined [-Werror,-Wmacro-redefined]
#define CLOCK_MONOTONIC (1)
^
/usr/include/time.h:156:9: note: previous definition is here
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
^
In file included from src/extern_sha1.c:28:
src/httplib_main.h:131:9: error: 'CLOCK_REALTIME' macro redefined [-Werror,-Wmacro-redefined]
#define CLOCK_REALTIME (2)
^
/usr/include/time.h:154:9: note: previous definition is here
#define CLOCK_REALTIME _CLOCK_REALTIME
^
2 errors generated.
make: *** [obj/extern_sha1.o] Error 1

Proper error reporting in httplib_start()

During startup of a server with a call to httplib_start(), there are many reasons why the start could potentially fail. Unfortunately error reporting back to the calling party is almost not existent. Only some httplib_cry() calls are in place, but these report to a file which may not be opened due to setting or other errors. Also Windows socket error codes are not compatible with Linux, and these errors are reported with an error number followed by "no error".

Error handling during startup must be better and reporting errors back to the application should be made much more friendly.

None of building option works

Hello,
I am following the building guide doc/Build.md to build the libhttp with socket enable. But I found
none of the building target works.

issue 1:
None of make option works. It works only with 'make' in the command and removing Werror in Makefile. I found the there is no target, help, build..., in the Makefile

$ make lib WITH_WEBSOCKET=1
make: Nothing to be done for 'lib'.

$ make build
make: *** No rule to make target 'build'. Stop.

$ make help
make: *** No rule to make target 'help'. Stop.

issue 2:
I am trying to build websocket_client in examples/websocket_client. Weird thing is that it removes the all libs and tries to copy libcivetweb.a which I cannot find this word(libcivetweb) in any file except all Makefile in the example directory.

examples/websocket_client$ make

make -C ../.. clean lib WITH_WEBSOCKET=1
make[1]: Entering directory '/home/tyler/Documents/project/libhttp'
/bin/rm -f obj/*.o
/bin/rm -f lib/libhttp.a
/bin/rm -f testmime
/bin/rm -f libhttpserver
make[1]: *** No rule to make target 'lib'. Stop.
make[1]: Leaving directory '/home/tyler/Documents/project/libhttp'
Makefile:31: recipe for target 'libcivetweb.a' failed
make: *** [libcivetweb.a] Error 2

XX_httplib_get_random() is not thread safe

Two static variables to store the state of two random generators. It won't hurt much probably because the outcome of the generator is "random" anyway, but we have to check if this is the best option.

Error handling should support debug levels

Currently error messages are either logged or discarded. It would be better to sort them in groups like informational, warning, error and failure and switch logging of them on and off with run time settings. Also grouping of errors based on subsystem (socket errors, file errors, general errors, etc) could be possible to give the application further control about the messages they will receive or ignore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.