Skip to content

Commit

Permalink
Merge branch 'main' into coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jun 13, 2024
2 parents d8b161b + 47a5d9a commit f370bbd
Show file tree
Hide file tree
Showing 22 changed files with 505 additions and 235 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
- name: gcov
run: |
cd ../re
gcov build/**/*.o
- name: install gcovr
Expand All @@ -48,7 +47,18 @@ jobs:
- name: coverage check
run: |
min_cov="64.4"
cov=$(~/.local/bin/gcovr -r . -s | grep lines | awk '{ print $2 }' | sed 's/%//')
min_cov="64.6"
mkdir html
cov=$(~/.local/bin/gcovr -r . --html-details html/index.html --json-summary | jq .line_percent)
echo "Coverage: ${cov}% (min $min_cov%)"
exit $(echo "$cov < $min_cov" | bc -l)
- name: coverage zip
run: |
zip -r coverage.zip html
- uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.zip
retention-days: 7
2 changes: 1 addition & 1 deletion .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:

- name: build
run: |
cmake -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=ON -DUSE_OPENSSL=OFF -DCMAKE_C_FLAGS="-Werror"
cmake -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=ON -DUSE_OPENSSL=OFF -DCMAKE_C_FLAGS="-Werror"
cmake --build build -- CODE_SIGNING_ALLOWED=NO
12 changes: 9 additions & 3 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04]
sanitizer: [thread, address]
sanitizer: [thread, address, undefined]
env:
CC: clang
CC: clang-17
CMAKE_GENERATOR: Ninja
CFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
CFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function"
ASAN_OPTIONS: fast_unwind_on_malloc=0

steps:
Expand All @@ -38,6 +38,12 @@ jobs:
run: |
sudo apt-get update && sudo apt-get install -y ninja-build
- name: Install clang-tools
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
sudo apt-get update && sudo apt-get install -y clang-17
- name: make info
run: |
echo "OS: ${{ matrix.os }}"
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ legend:

| System | Support type | Supported versions | Notes |
|---|---|---|---|
| Linux | Tier 1 | glibc >= 2.27 (Ubuntu 18.04) | |
| Linux | Tier 1 | glibc >= 2.27 | |
| Linux | Tier 1 | musl >= 1.2 | |
| macOS | Tier 1 | macOS >= 10.10 | |
| Windows | Tier 1 | >= Windows 8 | MinGW-w64, >= VS 2019 |
| Android | Tier 2 | | |
| iOS | Tier 2 | | |
| FreeBSD | Tier 2 | >= 11 | |
| OpenBSD | Tier 2 | >= 6.7 | |
| FreeBSD | Tier 2 | >= 12 | |
| OpenBSD | Tier 2 | >= 7.4 | |
| Linux | Tier 2 | uClibc | |


Expand All @@ -253,6 +254,7 @@ legend:
* GNU C Library (glibc)
* Windows C Run-Time Libraries (CRT)
* uClibc
* musl


### Supported compilers:
Expand Down
3 changes: 3 additions & 0 deletions include/re_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ int http_client_set_cert(struct http_cli *cli, const char *path);
int http_client_set_certpem(struct http_cli *cli, const char *pem);
int http_client_set_key(struct http_cli *cli, const char *path);
int http_client_set_keypem(struct http_cli *cli, const char *pem);
int http_client_use_chain(struct http_cli *cli, const char *path);
int http_client_use_chainpem(struct http_cli *cli, const char *chain,
int len_chain);

int http_client_set_session_reuse(struct http_cli *cli, bool enabled);
int http_client_set_tls_min_version(struct http_cli *cli, int version);
Expand Down
6 changes: 0 additions & 6 deletions include/re_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
#define INET6_ADDRSTRLEN 46
#endif

/** Length of IPv4/v6 address string */
#ifdef HAVE_INET6
#define NET_ADDRSTRLEN INET6_ADDRSTRLEN
#else
#define NET_ADDRSTRLEN INET_ADDRSTRLEN
#endif

/* forward declarations */
struct sa;
Expand Down
3 changes: 2 additions & 1 deletion include/re_sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ int sip_debug(struct re_printf *pf, const struct sip *sip);
int sip_send(struct sip *sip, void *sock, enum sip_transp tp,
const struct sa *dst, struct mbuf *mb);
int sip_send_conn(struct sip *sip, void *sock, enum sip_transp tp,
const struct sa *dst, struct mbuf *mb,
const struct sa *dst, char *host, struct mbuf *mb,
sip_conn_h *connh, void *arg);
void sip_set_trace_handler(struct sip *sip, sip_trace_h *traceh);

Expand Down Expand Up @@ -402,6 +402,7 @@ void sip_dialog_set_srcport(struct sip_dialog *dlg, uint16_t srcport);
uint16_t sip_dialog_srcport(struct sip_dialog *dlg);
const char *sip_dialog_uri(const struct sip_dialog *dlg);
uint32_t sip_dialog_lseq(const struct sip_dialog *dlg);
uint32_t sip_dialog_lseqinv(const struct sip_dialog *dlg);
enum sip_transp sip_dialog_tp(const struct sip_dialog *dlg);
bool sip_dialog_established(const struct sip_dialog *dlg);
bool sip_dialog_cmp(const struct sip_dialog *dlg, const struct sip_msg *msg);
Expand Down
3 changes: 3 additions & 0 deletions include/re_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ int tls_set_certificate_der(struct tls *tls, enum tls_keytype keytype,
const uint8_t *cert, size_t len_cert,
const uint8_t *key, size_t len_key);
int tls_set_certificate(struct tls *tls, const char *cert, size_t len);
int tls_set_certificate_chain_pem(struct tls *tls, const char *chain,
size_t len_chain);
int tls_set_certificate_chain(struct tls *tls, const char *path);
void tls_set_verify_client(struct tls *tls);
void tls_set_verify_client_trust_all(struct tls *tls);
int tls_set_verify_client_handler(struct tls_conn *tc, int depth,
Expand Down
52 changes: 52 additions & 0 deletions src/http/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,58 @@ int http_client_disable_verify_server(struct http_cli *cli)

return 0;
}


/**
* Change used certificate+key of TLS connection
*
* @param cli HTTP Client
* @param chain Cert (chain) + Key (PEM format)
* @param len_chain Length of certificate + key PEM string
*
* @return int 0 if success, otherwise errorcode
*/
int http_client_use_chainpem(struct http_cli *cli, const char *chain,
int len_chain)
{
if (!cli || !cli->tls)
return EINVAL;

int err = tls_set_certificate_chain_pem(cli->tls, chain, len_chain);
if (err)
return err;

cli->cert = mem_deref(cli->cert);
cli->key = mem_deref(cli->key);

return 0;
}


/**
* Change used certificate+key of TLS connection
*
* @param cli HTTP Client
* @param path Path to Cert (chain) + Key file (PEM format)
*
* @return int 0 if success, otherwise errorcode
*/
int http_client_use_chain(struct http_cli *cli, const char *path)
{
int err;

if (!cli || !cli->tls)
return EINVAL;

err = tls_set_certificate_chain(cli->tls, path);
if (err)
return err;

cli->cert = mem_deref(cli->cert);
cli->key = mem_deref(cli->key);

return 0;
}
#endif /* USE_TLS */


Expand Down
30 changes: 24 additions & 6 deletions src/sip/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct sip_dialog {
uint32_t hash;
uint32_t lseq;
uint32_t rseq;
uint32_t lseqinv;
size_t cpos;
size_t rpos;
enum sip_transp tp;
Expand Down Expand Up @@ -395,12 +396,13 @@ int sip_dialog_fork(struct sip_dialog **dlgp, struct sip_dialog *odlg,
if (!dlg)
return ENOMEM;

dlg->callid = mem_ref(odlg->callid);
dlg->ltag = mem_ref(odlg->ltag);
dlg->hash = odlg->hash;
dlg->lseq = odlg->lseq;
dlg->rseq = msg->req ? msg->cseq.num : 0;
dlg->tp = msg->tp;
dlg->callid = mem_ref(odlg->callid);
dlg->ltag = mem_ref(odlg->ltag);
dlg->hash = odlg->hash;
dlg->lseq = odlg->lseq;
dlg->lseqinv = odlg->lseqinv;
dlg->rseq = msg->req ? msg->cseq.num : 0;
dlg->tp = msg->tp;

err = pl_strdup(&dlg->uri, &addr.auri);
if (err)
Expand Down Expand Up @@ -570,6 +572,9 @@ int sip_dialog_encode(struct mbuf *mb, struct sip_dialog *dlg, uint32_t cseq,
if (!mb || !dlg || !met)
return EINVAL;

if (!strcmp(met, "INVITE"))
dlg->lseqinv = dlg->lseq;

err |= mbuf_write_mem(mb, mbuf_buf(dlg->mb), mbuf_get_left(dlg->mb));
err |= mbuf_printf(mb, "Call-ID: %s\r\n", dlg->callid);
err |= mbuf_printf(mb, "CSeq: %u %s\r\n", strcmp(met, "ACK") ?
Expand Down Expand Up @@ -661,6 +666,19 @@ uint32_t sip_dialog_lseq(const struct sip_dialog *dlg)
}


/**
* Get the local sequence number of the last sent INVITE
*
* @param dlg SIP Dialog
*
* @return Local sequence number
*/
uint32_t sip_dialog_lseqinv(const struct sip_dialog *dlg)
{
return dlg ? dlg->lseqinv : 0;
}


/**
* Check if a SIP Dialog is established
*
Expand Down
2 changes: 1 addition & 1 deletion src/sip/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static int request(struct sip_request *req, enum sip_transp tp,
}

if (!req->stateful) {
err = sip_send_conn(req->sip, NULL, tp, dst, mb,
err = sip_send_conn(req->sip, NULL, tp, dst, req->host, mb,
connect_handler, req);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/sip/sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ void sip_close(struct sip *sip, bool force)
* @return 0 if success, otherwise errorcode
*/
int sip_send_conn(struct sip *sip, void *sock, enum sip_transp tp,
const struct sa *dst, struct mbuf *mb,
const struct sa *dst, char *host, struct mbuf *mb,
sip_conn_h *connh, void *arg)
{
return sip_transp_send(NULL, sip, sock, tp, dst, NULL, mb, connh, NULL,
return sip_transp_send(NULL, sip, sock, tp, dst, host, mb, connh, NULL,
arg);
}

Expand Down
11 changes: 7 additions & 4 deletions src/sipsess/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg)
if (!msg || err || sip_request_loops(&sess->ls, msg->scode))
goto out;

if (!sip_dialog_cmp_half(sess->dlg, msg)
|| sip_dialog_lseqinv(sess->dlg) != msg->cseq.num)
goto out;

sdp = mbuf_get_left(msg->mb) > 0;

if (msg->scode < 200) {
Expand Down Expand Up @@ -148,15 +152,15 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg)
}
else if (msg->scode < 300) {

sess->established = true;

sess->hdrs = mem_deref(sess->hdrs);

err = sip_dialog_established(sess->dlg) ?
sip_dialog_update(sess->dlg, msg) :
sip_dialog_create(sess->dlg, msg);
if (err)
goto out;

if (sdp) {
if (sdp && !err) {
if (sess->neg_state == SDP_NEG_LOCAL_OFFER) {
sess->neg_state = SDP_NEG_DONE;
err = sess->answerh(msg, sess->arg);
Expand All @@ -179,7 +183,6 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg)
&& mbuf_get_left(desc))
sess->neg_state = SDP_NEG_DONE;

sess->established = true;
mem_deref(desc);

if (err || sess->terminated)
Expand Down
Loading

0 comments on commit f370bbd

Please sign in to comment.