Skip to content

Commit 5e7b2a7

Browse files
committed
fuzz-and-sonarqube-fixes
1 parent 7e1b4a9 commit 5e7b2a7

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

lib/roles/http/server/lejp-conf.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ lejp_globals_cb(struct lejp_ctx *ctx, char reason)
449449
struct lws_protocol_vhost_options *rej;
450450
char *p;
451451

452-
if (reason == LEJPCB_VAL_STR_START ||
453-
reason == LEJPCB_VAL_STR_CHUNK ||
454-
reason == LEJPCB_VAL_STR_END)
455-
if (lejp_string_unify_part(ctx, &a->ac, reason))
456-
return 1;
452+
if ((reason == LEJPCB_VAL_STR_START ||
453+
reason == LEJPCB_VAL_STR_CHUNK ||
454+
reason == LEJPCB_VAL_STR_END) &&
455+
lejp_string_unify_part(ctx, &a->ac, reason))
456+
return 1;
457457

458458
/* we only match on the prepared path strings */
459459
if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match)
@@ -605,11 +605,11 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason)
605605
char *p, *p1;
606606
int n;
607607

608-
if (reason == LEJPCB_VAL_STR_START ||
609-
reason == LEJPCB_VAL_STR_CHUNK ||
610-
reason == LEJPCB_VAL_STR_END)
611-
if (lejp_string_unify_part(ctx, &a->ac, reason))
612-
return 1;
608+
if ((reason == LEJPCB_VAL_STR_START ||
609+
reason == LEJPCB_VAL_STR_CHUNK ||
610+
reason == LEJPCB_VAL_STR_END) &&
611+
lejp_string_unify_part(ctx, &a->ac, reason))
612+
return 1;
613613

614614
#if 0
615615
lwsl_notice(" %d: %s (%d)\n", reason, ctx->path, ctx->path_match);

lib/tls/gnutls/gnutls-tls.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,12 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh,
292292
} else if (cert_mem && cert_mem_len && key_mem && key_mem_len) {
293293
gnutls_datum_t dcert, dkey;
294294

295-
dcert.data = (unsigned char *)cert_mem;
295+
/* gnutls_datum_t data lacks const, so has to alias the
296+
* caller's const buffers via a cast that doesn't drop it
297+
*/
298+
dcert.data = (unsigned char *)(uintptr_t)cert_mem;
296299
dcert.size = (unsigned)cert_mem_len;
297-
dkey.data = (unsigned char *)key_mem;
300+
dkey.data = (unsigned char *)(uintptr_t)key_mem;
298301
dkey.size = (unsigned)key_mem_len;
299302

300303
if (gnutls_certificate_set_x509_key_mem(

minimal-examples-lowlevel/api-tests/api-test-lws_stub/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#if !defined(WIN32)
2020
#include <unistd.h>
2121
#include <sys/wait.h>
22+
#include <time.h>
2223
#else
2324
#include <process.h>
2425
#include <io.h>
@@ -73,7 +74,7 @@ stub_gone_marker_path(void)
7374
{
7475
static char path[300];
7576

76-
lws_snprintf(path, sizeof(path), "/tmp/lws-%s.gone", STUB_NAME_P3);
77+
lws_snprintf(path, sizeof(path), "/tmp/lws-%s.gone", STUB_NAME_P3); // NOSONAR
7778

7879
return path;
7980
}
@@ -253,7 +254,7 @@ static void stub_parent_gone_cb(void *user)
253254
return;
254255

255256
/* leave a marker so the test can prove this ran in the stub child */
256-
lws_snprintf(path, sizeof(path), "/tmp/lws-%s.gone", stub_name);
257+
lws_snprintf(path, sizeof(path), "/tmp/lws-%s.gone", stub_name); // NOSONAR
257258
fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0600);
258259
if (fd >= 0) {
259260
if (write(fd, &ok, 1) < 0)
@@ -279,7 +280,7 @@ static int run_stub(struct lws_context *cx, const char *stub_name)
279280
sc.stub_name = stub_name;
280281
sc.uds_path = stub_uds_path(stub_name);
281282
sc.protocols = stub_protocols;
282-
sc.user = (void *)stub_name;
283+
sc.user = (void *)(uintptr_t)stub_name;
283284
sc.parent_gone_cb = stub_parent_gone_cb;
284285

285286
if (lws_stub_server_init(&sc, secret, extra, sizeof(extra)) < 0) {
@@ -594,10 +595,11 @@ phase3(int argc, const char **argv)
594595
*/
595596
start = lws_now_usecs();
596597
while (lws_now_usecs() - start < 10000000) { /* 10s */
598+
struct timespec ts = { .tv_nsec = 100 * 1000 * 1000 };
597599
if (gone_marker_present() &&
598600
stat(stub_uds_path(STUB_NAME_P3), &st))
599601
break;
600-
usleep(100000);
602+
nanosleep(&ts, NULL);
601603
}
602604

603605
if (!gone_marker_present()) {

0 commit comments

Comments
 (0)