Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/fuzzers/cib_file_fuzzer.c b/fuzzers/cib_file_fuzzer.c
index 579f34c8c7..1bd1d2b877 100644
--- a/fuzzers/cib_file_fuzzer.c
+++ b/fuzzers/cib_file_fuzzer.c
@@ -1,41 +1,48 @@
/*
* Copyright 2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
+
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <crm_internal.h>
#include <crm/cib/internal.h>
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
- char *filename;
- int fd;
+ char *filename = NULL;
+ int fd = 0;
- // Have at least some data
- if (size < 5) {
- return 0;
- }
+ // Have at least some data
+ if (size < 5) {
+ return -1; // Do not add input to testing corpus
+ }
- filename = crm_strdup_printf("%s/libfuzzer.XXXXXX", pcmk__get_tmpdir());
- fd = mkstemp(filename);
- if (fd == -1) {
- return 0;
- }
- write(fd, data, size);
- close(fd);
+ filename = crm_strdup_printf("%s/libfuzzer.XXXXXX", pcmk__get_tmpdir());
+ fd = mkstemp(filename);
+ if (fd == -1) {
+ free(filename);
+ return 0;
+ }
+ if (write(fd, data, size) < 0) {
+ close(fd);
+ unlink(filename);
+ free(filename);
+ return 0;
+ }
+ close(fd);
- cib_file_read_and_verify(filename, NULL, NULL);
+ cib_file_read_and_verify(filename, NULL, NULL);
- unlink(filename);
- free(filename);
+ unlink(filename);
+ free(filename);
- return 0;
+ return 0;
}
diff --git a/fuzzers/iso8601_fuzzer.c b/fuzzers/iso8601_fuzzer.c
index cb83cb8f2a..0e151c6dbd 100644
--- a/fuzzers/iso8601_fuzzer.c
+++ b/fuzzers/iso8601_fuzzer.c
@@ -1,45 +1,46 @@
/*
* Copyright 2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
+
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <crm/common/util.h>
-#include <crm/common/iso8601.h>
-#include <crm/common/iso8601_internal.h>
-
+#include <crm/common/internal.h>
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
- char *ns;
- char *result;
- time_t epoch;
- pcmk__time_hr_t *now;
+ char *ns = NULL;
+ char *result = NULL;
+ time_t epoch = 0;
+ pcmk__time_hr_t *now = NULL;
+ crm_time_period_t *period = NULL;
+
+ // Ensure we have enough data.
+ if (size < 10) {
+ return -1; // Do not add input to testing corpus
+ }
+ ns = pcmk__assert_alloc(1, size + 1);
+ memcpy(ns, data, size);
+
+ period = crm_time_parse_period(ns);
+ crm_time_free_period(period);
+
+ now = pcmk__time_hr_new(ns);
+ pcmk__time_hr_free(now);
+
+ now = pcmk__time_hr_now(&epoch);
+ result = pcmk__time_format_hr(ns, now);
+ pcmk__time_hr_free(now);
+ free(result);
- // Ensure we have enough data.
- if (size < 10) {
+ free(ns);
return 0;
- }
- ns = malloc(size+1);
- memcpy(ns, data, size);
- ns[size] = '\0';
-
- crm_time_parse_period(ns);
- pcmk__time_hr_new(ns);
-
- epoch = 0;
- now = NULL;
- now = pcmk__time_hr_now(&epoch);
- result = pcmk__time_format_hr(ns, now);
- free(result);
-
- free(ns);
- return 0;
}
diff --git a/fuzzers/strings_fuzzer.c b/fuzzers/strings_fuzzer.c
index 510c75fd68..f8dfc8e39f 100644
--- a/fuzzers/strings_fuzzer.c
+++ b/fuzzers/strings_fuzzer.c
@@ -1,40 +1,40 @@
/*
* Copyright 2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
+
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <glib.h>
#include <crm/common/options.h>
#include <crm/common/util.h>
-#include <crm/common/util_compat.h>
-#include <crm/common/strings_internal.h>
+#include <crm/common/internal.h>
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
- char *ns;
- guint res;
+ char *ns = NULL;
+ guint res = 0U;
- if (size < 10) {
- return 0;
- }
- ns = malloc(size+1);
- memcpy(ns, data, size);
- ns[size] = '\0';
+ if (size < 10) {
+ return -1; // Do not add input to testing corpus
+ }
+ ns = pcmk__assert_alloc(1, size + 1);
+ memcpy(ns, data, size);
+ ns[size] = '\0';
- pcmk__numeric_strcasecmp(ns, ns);
- pcmk__trim(ns);
- pcmk_parse_interval_spec(ns, &res);
- crm_get_msec(ns);
+ pcmk__numeric_strcasecmp(ns, ns);
+ pcmk__trim(ns);
+ pcmk_parse_interval_spec(ns, &res);
+ crm_get_msec(ns);
- free(ns);
- return 0;
+ free(ns);
+ return 0;
}
diff --git a/fuzzers/utils_fuzzer.c b/fuzzers/utils_fuzzer.c
index 73c3f4e1d4..2cb3a5339b 100644
--- a/fuzzers/utils_fuzzer.c
+++ b/fuzzers/utils_fuzzer.c
@@ -1,34 +1,34 @@
/*
* Copyright 2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <crm/common/util.h>
-#include <crm/common/util_compat.h>
+#include <crm/common/internal.h>
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
- char *ns;
- guint result;
+ char *ns = NULL;
+ guint result = 0U;
- if (size < 10) {
- return 0;
- }
- ns = malloc(size+1);
- memcpy(ns, data, size);
- ns[size] = '\0';
+ if (size < 10) {
+ return -1; // Do not add input to testing corpus
+ }
+ ns = pcmk__assert_alloc(1, size + 1);
+ memcpy(ns, data, size);
+ ns[size] = '\0';
- pcmk_parse_interval_spec(ns, &result);
+ pcmk_parse_interval_spec(ns, &result);
- free(ns);
- return 0;
+ free(ns);
+ return 0;
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Apr 21, 7:09 PM (22 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1665392
Default Alt Text
(6 KB)

Event Timeline