Skip to content

Commit f370bbd

Browse files
committed
Merge branch 'main' into coverity
2 parents d8b161b + 47a5d9a commit f370bbd

22 files changed

+505
-235
lines changed

.github/workflows/coverage.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
4040
- name: gcov
4141
run: |
42-
cd ../re
4342
gcov build/**/*.o
4443
4544
- name: install gcovr
@@ -48,7 +47,18 @@ jobs:
4847
4948
- name: coverage check
5049
run: |
51-
min_cov="64.4"
52-
cov=$(~/.local/bin/gcovr -r . -s | grep lines | awk '{ print $2 }' | sed 's/%//')
50+
min_cov="64.6"
51+
mkdir html
52+
cov=$(~/.local/bin/gcovr -r . --html-details html/index.html --json-summary | jq .line_percent)
5353
echo "Coverage: ${cov}% (min $min_cov%)"
5454
exit $(echo "$cov < $min_cov" | bc -l)
55+
56+
- name: coverage zip
57+
run: |
58+
zip -r coverage.zip html
59+
60+
- uses: actions/upload-artifact@v4
61+
with:
62+
name: coverage
63+
path: coverage.zip
64+
retention-days: 7

.github/workflows/ios.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717

1818
- name: build
1919
run: |
20-
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"
20+
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"
2121
cmake --build build -- CODE_SIGNING_ALLOWED=NO

.github/workflows/sanitizers.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [ubuntu-22.04]
18-
sanitizer: [thread, address]
18+
sanitizer: [thread, address, undefined]
1919
env:
20-
CC: clang
20+
CC: clang-17
2121
CMAKE_GENERATOR: Ninja
22-
CFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
22+
CFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function"
2323
ASAN_OPTIONS: fast_unwind_on_malloc=0
2424

2525
steps:
@@ -38,6 +38,12 @@ jobs:
3838
run: |
3939
sudo apt-get update && sudo apt-get install -y ninja-build
4040
41+
- name: Install clang-tools
42+
run: |
43+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
44+
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
45+
sudo apt-get update && sudo apt-get install -y clang-17
46+
4147
- name: make info
4248
run: |
4349
echo "OS: ${{ matrix.os }}"

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,14 @@ legend:
223223

224224
| System | Support type | Supported versions | Notes |
225225
|---|---|---|---|
226-
| Linux | Tier 1 | glibc >= 2.27 (Ubuntu 18.04) | |
226+
| Linux | Tier 1 | glibc >= 2.27 | |
227+
| Linux | Tier 1 | musl >= 1.2 | |
227228
| macOS | Tier 1 | macOS >= 10.10 | |
228229
| Windows | Tier 1 | >= Windows 8 | MinGW-w64, >= VS 2019 |
229230
| Android | Tier 2 | | |
230231
| iOS | Tier 2 | | |
231-
| FreeBSD | Tier 2 | >= 11 | |
232-
| OpenBSD | Tier 2 | >= 6.7 | |
232+
| FreeBSD | Tier 2 | >= 12 | |
233+
| OpenBSD | Tier 2 | >= 7.4 | |
233234
| Linux | Tier 2 | uClibc | |
234235

235236

@@ -253,6 +254,7 @@ legend:
253254
* GNU C Library (glibc)
254255
* Windows C Run-Time Libraries (CRT)
255256
* uClibc
257+
* musl
256258

257259

258260
### Supported compilers:

include/re_http.h

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ int http_client_set_cert(struct http_cli *cli, const char *path);
169169
int http_client_set_certpem(struct http_cli *cli, const char *pem);
170170
int http_client_set_key(struct http_cli *cli, const char *path);
171171
int http_client_set_keypem(struct http_cli *cli, const char *pem);
172+
int http_client_use_chain(struct http_cli *cli, const char *path);
173+
int http_client_use_chainpem(struct http_cli *cli, const char *chain,
174+
int len_chain);
172175

173176
int http_client_set_session_reuse(struct http_cli *cli, bool enabled);
174177
int http_client_set_tls_min_version(struct http_cli *cli, int version);

include/re_net.h

-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
#define INET6_ADDRSTRLEN 46
2727
#endif
2828

29-
/** Length of IPv4/v6 address string */
30-
#ifdef HAVE_INET6
31-
#define NET_ADDRSTRLEN INET6_ADDRSTRLEN
32-
#else
33-
#define NET_ADDRSTRLEN INET_ADDRSTRLEN
34-
#endif
3529

3630
/* forward declarations */
3731
struct sa;

include/re_sip.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ int sip_debug(struct re_printf *pf, const struct sip *sip);
303303
int sip_send(struct sip *sip, void *sock, enum sip_transp tp,
304304
const struct sa *dst, struct mbuf *mb);
305305
int sip_send_conn(struct sip *sip, void *sock, enum sip_transp tp,
306-
const struct sa *dst, struct mbuf *mb,
306+
const struct sa *dst, char *host, struct mbuf *mb,
307307
sip_conn_h *connh, void *arg);
308308
void sip_set_trace_handler(struct sip *sip, sip_trace_h *traceh);
309309

@@ -402,6 +402,7 @@ void sip_dialog_set_srcport(struct sip_dialog *dlg, uint16_t srcport);
402402
uint16_t sip_dialog_srcport(struct sip_dialog *dlg);
403403
const char *sip_dialog_uri(const struct sip_dialog *dlg);
404404
uint32_t sip_dialog_lseq(const struct sip_dialog *dlg);
405+
uint32_t sip_dialog_lseqinv(const struct sip_dialog *dlg);
405406
enum sip_transp sip_dialog_tp(const struct sip_dialog *dlg);
406407
bool sip_dialog_established(const struct sip_dialog *dlg);
407408
bool sip_dialog_cmp(const struct sip_dialog *dlg, const struct sip_msg *msg);

include/re_tls.h

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ int tls_set_certificate_der(struct tls *tls, enum tls_keytype keytype,
5656
const uint8_t *cert, size_t len_cert,
5757
const uint8_t *key, size_t len_key);
5858
int tls_set_certificate(struct tls *tls, const char *cert, size_t len);
59+
int tls_set_certificate_chain_pem(struct tls *tls, const char *chain,
60+
size_t len_chain);
61+
int tls_set_certificate_chain(struct tls *tls, const char *path);
5962
void tls_set_verify_client(struct tls *tls);
6063
void tls_set_verify_client_trust_all(struct tls *tls);
6164
int tls_set_verify_client_handler(struct tls_conn *tc, int depth,

src/http/client.c

+52
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,58 @@ int http_client_disable_verify_server(struct http_cli *cli)
12601260

12611261
return 0;
12621262
}
1263+
1264+
1265+
/**
1266+
* Change used certificate+key of TLS connection
1267+
*
1268+
* @param cli HTTP Client
1269+
* @param chain Cert (chain) + Key (PEM format)
1270+
* @param len_chain Length of certificate + key PEM string
1271+
*
1272+
* @return int 0 if success, otherwise errorcode
1273+
*/
1274+
int http_client_use_chainpem(struct http_cli *cli, const char *chain,
1275+
int len_chain)
1276+
{
1277+
if (!cli || !cli->tls)
1278+
return EINVAL;
1279+
1280+
int err = tls_set_certificate_chain_pem(cli->tls, chain, len_chain);
1281+
if (err)
1282+
return err;
1283+
1284+
cli->cert = mem_deref(cli->cert);
1285+
cli->key = mem_deref(cli->key);
1286+
1287+
return 0;
1288+
}
1289+
1290+
1291+
/**
1292+
* Change used certificate+key of TLS connection
1293+
*
1294+
* @param cli HTTP Client
1295+
* @param path Path to Cert (chain) + Key file (PEM format)
1296+
*
1297+
* @return int 0 if success, otherwise errorcode
1298+
*/
1299+
int http_client_use_chain(struct http_cli *cli, const char *path)
1300+
{
1301+
int err;
1302+
1303+
if (!cli || !cli->tls)
1304+
return EINVAL;
1305+
1306+
err = tls_set_certificate_chain(cli->tls, path);
1307+
if (err)
1308+
return err;
1309+
1310+
cli->cert = mem_deref(cli->cert);
1311+
cli->key = mem_deref(cli->key);
1312+
1313+
return 0;
1314+
}
12631315
#endif /* USE_TLS */
12641316

12651317

src/sip/dialog.c

+24-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct sip_dialog {
3434
uint32_t hash;
3535
uint32_t lseq;
3636
uint32_t rseq;
37+
uint32_t lseqinv;
3738
size_t cpos;
3839
size_t rpos;
3940
enum sip_transp tp;
@@ -395,12 +396,13 @@ int sip_dialog_fork(struct sip_dialog **dlgp, struct sip_dialog *odlg,
395396
if (!dlg)
396397
return ENOMEM;
397398

398-
dlg->callid = mem_ref(odlg->callid);
399-
dlg->ltag = mem_ref(odlg->ltag);
400-
dlg->hash = odlg->hash;
401-
dlg->lseq = odlg->lseq;
402-
dlg->rseq = msg->req ? msg->cseq.num : 0;
403-
dlg->tp = msg->tp;
399+
dlg->callid = mem_ref(odlg->callid);
400+
dlg->ltag = mem_ref(odlg->ltag);
401+
dlg->hash = odlg->hash;
402+
dlg->lseq = odlg->lseq;
403+
dlg->lseqinv = odlg->lseqinv;
404+
dlg->rseq = msg->req ? msg->cseq.num : 0;
405+
dlg->tp = msg->tp;
404406

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

575+
if (!strcmp(met, "INVITE"))
576+
dlg->lseqinv = dlg->lseq;
577+
573578
err |= mbuf_write_mem(mb, mbuf_buf(dlg->mb), mbuf_get_left(dlg->mb));
574579
err |= mbuf_printf(mb, "Call-ID: %s\r\n", dlg->callid);
575580
err |= mbuf_printf(mb, "CSeq: %u %s\r\n", strcmp(met, "ACK") ?
@@ -661,6 +666,19 @@ uint32_t sip_dialog_lseq(const struct sip_dialog *dlg)
661666
}
662667

663668

669+
/**
670+
* Get the local sequence number of the last sent INVITE
671+
*
672+
* @param dlg SIP Dialog
673+
*
674+
* @return Local sequence number
675+
*/
676+
uint32_t sip_dialog_lseqinv(const struct sip_dialog *dlg)
677+
{
678+
return dlg ? dlg->lseqinv : 0;
679+
}
680+
681+
664682
/**
665683
* Check if a SIP Dialog is established
666684
*

src/sip/request.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int request(struct sip_request *req, enum sip_transp tp,
233233
}
234234

235235
if (!req->stateful) {
236-
err = sip_send_conn(req->sip, NULL, tp, dst, mb,
236+
err = sip_send_conn(req->sip, NULL, tp, dst, req->host, mb,
237237
connect_handler, req);
238238
}
239239
else {

src/sip/sip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ void sip_close(struct sip *sip, bool force)
210210
* @return 0 if success, otherwise errorcode
211211
*/
212212
int sip_send_conn(struct sip *sip, void *sock, enum sip_transp tp,
213-
const struct sa *dst, struct mbuf *mb,
213+
const struct sa *dst, char *host, struct mbuf *mb,
214214
sip_conn_h *connh, void *arg)
215215
{
216-
return sip_transp_send(NULL, sip, sock, tp, dst, NULL, mb, connh, NULL,
216+
return sip_transp_send(NULL, sip, sock, tp, dst, host, mb, connh, NULL,
217217
arg);
218218
}
219219

src/sipsess/connect.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg)
9191
if (!msg || err || sip_request_loops(&sess->ls, msg->scode))
9292
goto out;
9393

94+
if (!sip_dialog_cmp_half(sess->dlg, msg)
95+
|| sip_dialog_lseqinv(sess->dlg) != msg->cseq.num)
96+
goto out;
97+
9498
sdp = mbuf_get_left(msg->mb) > 0;
9599

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

155+
sess->established = true;
156+
151157
sess->hdrs = mem_deref(sess->hdrs);
152158

153159
err = sip_dialog_established(sess->dlg) ?
154160
sip_dialog_update(sess->dlg, msg) :
155161
sip_dialog_create(sess->dlg, msg);
156-
if (err)
157-
goto out;
158162

159-
if (sdp) {
163+
if (sdp && !err) {
160164
if (sess->neg_state == SDP_NEG_LOCAL_OFFER) {
161165
sess->neg_state = SDP_NEG_DONE;
162166
err = sess->answerh(msg, sess->arg);
@@ -179,7 +183,6 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg)
179183
&& mbuf_get_left(desc))
180184
sess->neg_state = SDP_NEG_DONE;
181185

182-
sess->established = true;
183186
mem_deref(desc);
184187

185188
if (err || sess->terminated)

0 commit comments

Comments
 (0)