Enable -Wwrite-strings

Also, fix leak from ztest_global_vars_to_zdb_args()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13348
This commit is contained in:
наб
2022-04-19 20:38:30 +02:00
committed by Brian Behlendorf
parent e7d90362e5
commit a926aab902
99 changed files with 633 additions and 717 deletions
+3 -3
View File
@@ -51,7 +51,7 @@
typedef struct timetest {
int type;
char *name;
const char *name;
int (*func)(const char *pfile);
} timetest_t;
@@ -260,7 +260,7 @@ static int
do_xattr(const char *pfile)
{
int ret = 0;
char *value = "user.value";
const char *value = "user.value";
if (pfile == NULL) {
return (-1);
@@ -306,7 +306,7 @@ int
main(void)
{
int i, ret, fd;
char *penv[] = {"TESTDIR", "TESTFILE0"};
const char *penv[] = {"TESTDIR", "TESTFILE0"};
(void) atexit(cleanup);
+1 -1
View File
@@ -47,7 +47,7 @@ static char dirpath[256];
int
main(int argc, char **argv)
{
char *cp1 = "";
const char *cp1 = "";
int i = 0;
int ret = 0;
int testdd = 0;
+5 -5
View File
@@ -130,7 +130,7 @@ read_map(const char *filename, nvlist_t **allcfgs)
* for freeing the configuration returned.
*/
static int
read_map_key(const char *filename, char *key, nvlist_t **cfg)
read_map_key(const char *filename, const char *key, nvlist_t **cfg)
{
nvlist_t *allcfgs, *foundcfg = NULL;
int error;
@@ -320,8 +320,8 @@ write_map_key(const char *filename, char *key, draid_map_t *map,
}
static void
dump_map(draid_map_t *map, char *key, double worst_ratio, double avg_ratio,
int verbose)
dump_map(draid_map_t *map, const char *key, double worst_ratio,
double avg_ratio, int verbose)
{
if (verbose == 0) {
return;
@@ -363,7 +363,7 @@ dump_map(draid_map_t *map, char *key, double worst_ratio, double avg_ratio,
}
static void
dump_map_nv(char *key, nvlist_t *cfg, int verbose)
dump_map_nv(const char *key, nvlist_t *cfg, int verbose)
{
draid_map_t map;
uint_t c;
@@ -385,7 +385,7 @@ dump_map_nv(char *key, nvlist_t *cfg, int verbose)
* Print a summary of the mapping.
*/
static int
dump_map_key(const char *filename, char *key, int verbose)
dump_map_key(const char *filename, const char *key, int verbose)
{
nvlist_t *cfg;
int error;
+2 -3
View File
@@ -25,10 +25,9 @@
#include <errno.h>
static void
usage(char *msg, int exit_value)
usage(const char *msg, int exit_value)
{
(void) fprintf(stderr, "get_diff file redacted_file\n");
(void) fprintf(stderr, "%s\n", msg);
(void) fprintf(stderr, "usage: get_diff file redacted_file\n%s\n", msg);
exit(exit_value);
}
+2 -2
View File
@@ -596,13 +596,13 @@ test_channel_program(const char *pool)
"arg = ...\n"
"argv = arg[\"argv\"]\n"
"return argv[1]";
char *const argv[1] = { "Hello World!" };
const char *const argv[1] = { "Hello World!" };
nvlist_t *required = fnvlist_alloc();
nvlist_t *optional = fnvlist_alloc();
nvlist_t *args = fnvlist_alloc();
fnvlist_add_string(required, "program", program);
fnvlist_add_string_array(args, "argv", (const char * const *)argv, 1);
fnvlist_add_string_array(args, "argv", argv, 1);
fnvlist_add_nvlist(required, "arg", args);
fnvlist_add_boolean_value(optional, "sync", B_TRUE);
+2 -2
View File
@@ -32,14 +32,14 @@
static __attribute__((noreturn)) void
usage(char *progname)
usage(const char *progname)
{
(void) fprintf(stderr, "Usage: %s <dirname|filename>\n", progname);
exit(1);
}
static __attribute__((noreturn)) void
fail(char *err)
fail(const char *err)
{
perror(err);
exit(1);
+8 -10
View File
@@ -21,13 +21,11 @@
#include <unistd.h>
#include <sys/param.h>
#define MAX_INT_LENGTH 10
static void
usage(char *msg, int exit_value)
usage(const char *msg, int exit_value)
{
(void) fprintf(stderr, "mkfiles basename max_file [min_file]\n");
(void) fprintf(stderr, "%s\n", msg);
(void) fprintf(stderr, "usage: mkfiles basename max_file [min_file]\n"
"%s\n", msg);
exit(exit_value);
}
@@ -40,13 +38,13 @@ main(int argc, char **argv)
char buf[MAXPATHLEN];
if (argc < 3 || argc > 4)
usage("Invalid number of arguments", -1);
usage("Invalid number of arguments", 1);
if (sscanf(argv[2], "%u", &numfiles) != 1)
usage("Invalid maximum file", -2);
usage("Invalid maximum file", 2);
if (argc == 4 && sscanf(argv[3], "%u", &first_file) != 1)
usage("Invalid first file", -3);
usage("Invalid first file", 3);
for (i = first_file; i < first_file + numfiles; i++) {
int fd;
@@ -54,11 +52,11 @@ main(int argc, char **argv)
if ((fd = open(buf, O_CREAT | O_EXCL, O_RDWR)) == -1) {
(void) fprintf(stderr, "Failed to create %s %s\n", buf,
strerror(errno));
return (-4);
return (4);
} else if (fchown(fd, getuid(), getgid()) < 0) {
(void) fprintf(stderr, "Failed to chown %s %s\n", buf,
strerror(errno));
return (-5);
return (5);
}
(void) close(fd);
}
+1 -1
View File
@@ -153,7 +153,7 @@ crtfile(char *pname)
{
int fd = -1;
int i, size;
char *context = "0123456789ABCDF";
const char *context = "0123456789ABCDF";
char *pbuf;
if (pname == NULL) {
+3 -3
View File
@@ -84,7 +84,7 @@ nvlist_equal(nvlist_t *nvla, nvlist_t *nvlb)
static void
test(const char *testname, boolean_t expect_success, boolean_t expect_match)
{
char *progstr = "input = ...; return {output=input}";
const char *progstr = "input = ...; return {output=input}";
nvlist_t *outnvl;
@@ -230,8 +230,8 @@ run_tests(void)
test("uint64_array", B_FALSE, B_FALSE);
}
{
char *const val[2] = { "0", "1" };
fnvlist_add_string_array(nvl, key, (const char **)val, 2);
const char *val[2] = { "0", "1" };
fnvlist_add_string_array(nvl, key, val, 2);
test("string_array", B_TRUE, B_FALSE);
}
{
+1 -1
View File
@@ -49,7 +49,7 @@
int
main(int argc, char **argv)
{
char *filename = "badfile";
const char *filename = "badfile";
size_t size = 4395;
size_t idx = 0;
char *buf = NULL;
+1 -1
View File
@@ -27,7 +27,7 @@ static char *ifile = NULL;
static char *ofile = NULL;
static int stride = 0;
static int seek = 0;
static char *execname = "stride_dd";
static const char *execname = "stride_dd";
static void usage(void);
static void parse_options(int argc, char *argv[]);
+8 -10
View File
@@ -91,8 +91,8 @@ static int size_is_random = 0;
static int value_is_random = 0;
static int keep_files = 0;
static int phase = PHASE_ALL;
static char path[PATH_MAX] = "/tmp/xattrtest";
static char script[PATH_MAX] = "/bin/true";
static const char *path = "/tmp/xattrtest";
static const char *script = "/bin/true";
static char xattrbytes[XATTR_SIZE_MAX];
static int
@@ -161,8 +161,7 @@ parse_args(int argc, char **argv)
}
break;
case 'p':
strncpy(path, optarg, PATH_MAX);
path[PATH_MAX - 1] = '\0';
path = optarg;
break;
case 'c':
synccaches = 1;
@@ -171,8 +170,7 @@ parse_args(int argc, char **argv)
dropcaches = 1;
break;
case 't':
strncpy(script, optarg, PATH_MAX);
script[PATH_MAX - 1] = '\0';
script = optarg;
break;
case 'e':
seed = strtol(optarg, NULL, 0);
@@ -291,9 +289,9 @@ run_process(const char *path, char *argv[])
}
static int
post_hook(char *phase)
post_hook(const char *phase)
{
char *argv[3] = { script, phase, (char *)0 };
char *argv[3] = { (char *)script, (char *)phase, NULL };
int rc;
if (synccaches)
@@ -517,9 +515,9 @@ getxattrs(void)
int i, j, rnd_size, shift, rc = 0;
char name[XATTR_NAME_MAX];
char *verify_value = NULL;
char *verify_string;
const char *verify_string;
char *value = NULL;
char *value_string;
const char *value_string;
char *file = NULL;
struct timeval start, stop;
double seconds;
@@ -29,16 +29,16 @@
*/
typedef struct hkdf_tv {
/* test vector input values */
char *ikm;
const char *ikm;
uint_t ikm_len;
char *salt;
const char *salt;
uint_t salt_len;
char *info;
const char *info;
uint_t info_len;
uint_t okm_len;
/* expected output */
char *okm;
const char *okm;
} hkdf_tv_t;
/*
@@ -48,7 +48,7 @@ typedef struct hkdf_tv {
* The current vectors were taken from:
* https://www.kullo.net/blog/hkdf-sha-512-test-vectors/
*/
static hkdf_tv_t test_vectors[] = {
static const hkdf_tv_t test_vectors[] = {
{
.ikm = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
@@ -170,7 +170,7 @@ static hkdf_tv_t test_vectors[] = {
};
static void
hexdump(char *str, uint8_t *src, uint_t len)
hexdump(const char *str, uint8_t *src, uint_t len)
{
printf("\t%s\t", str);
for (int i = 0; i < len; i++)
@@ -179,7 +179,7 @@ hexdump(char *str, uint8_t *src, uint_t len)
}
static int
run_test(int i, hkdf_tv_t *tv)
run_test(int i, const hkdf_tv_t *tv)
{
int ret;
uint8_t good[SHA512_DIGEST_LENGTH];
@@ -8,6 +8,7 @@
#include <errno.h>
#include <string.h>
#include <time.h>
#include <err.h>
/* backward compat in case it's not defined */
#ifndef O_TMPFILE
@@ -33,75 +34,45 @@ fill_random(char *buf, int len)
{
srand(time(NULL));
for (int i = 0; i < len; i++)
buf[i] = (char)rand();
buf[i] = (char)(rand() % 0xFF);
}
int
main(void)
{
int i, fd;
char buf1[BSZ], buf2[BSZ] = {};
char *penv[] = {"TESTDIR"};
char buf1[BSZ], buf2[BSZ] = {0};
(void) fprintf(stdout, "Verify O_TMPFILE is working properly.\n");
/*
* Get the environment variable values.
*/
for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
if ((penv[i] = getenv(penv[i])) == NULL) {
(void) fprintf(stderr, "getenv(penv[%d])\n", i);
exit(1);
}
}
const char *testdir = getenv("TESTDIR");
if (testdir == NULL)
errx(1, "getenv(\"TESTDIR\")");
fill_random(buf1, BSZ);
fd = open(penv[0], O_RDWR|O_TMPFILE, 0666);
if (fd < 0) {
perror("open");
exit(2);
}
int fd = open(testdir, O_RDWR|O_TMPFILE, 0666);
if (fd < 0)
err(2, "open(%s)", testdir);
if (write(fd, buf1, BSZ) < 0) {
perror("write");
close(fd);
exit(3);
}
if (write(fd, buf1, BSZ) < 0)
err(3, "write");
if (pread(fd, buf2, BSZ, 0) < 0) {
perror("pread");
close(fd);
exit(4);
}
if (pread(fd, buf2, BSZ, 0) < 0)
err(4, "pread");
if (memcmp(buf1, buf2, BSZ) != 0) {
fprintf(stderr, "data corrupted\n");
close(fd);
exit(5);
}
if (memcmp(buf1, buf2, BSZ) != 0)
errx(5, "data corrupted");
memset(buf2, 0, BSZ);
if (fsetxattr(fd, "user.test", buf1, BSZ, 0) < 0) {
perror("fsetxattr");
close(fd);
exit(6);
}
if (fsetxattr(fd, "user.test", buf1, BSZ, 0) < 0)
err(6, "pread");
if (fgetxattr(fd, "user.test", buf2, BSZ) < 0) {
perror("fgetxattr");
close(fd);
exit(7);
}
if (fgetxattr(fd, "user.test", buf2, BSZ) < 0)
err(7, "fgetxattr");
if (memcmp(buf1, buf2, BSZ) != 0) {
fprintf(stderr, "xattr corrupted\n");
close(fd);
exit(8);
}
close(fd);
if (memcmp(buf1, buf2, BSZ) != 0)
errx(8, "xattr corrupted\n");
return (0);
}
@@ -6,6 +6,7 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <err.h>
/* backward compat in case it's not defined */
#ifndef O_TMPFILE
@@ -24,12 +25,27 @@
*
*/
static void
run(const char *op)
{
int ret;
char buf[50];
sprintf(buf, "sudo -E zpool %s $TESTPOOL", op);
if ((ret = system(buf)) != 0) {
if (ret == -1)
err(4, "system \"zpool %s\"", op);
else
errx(4, "zpool %s exited %d\n",
op, WEXITSTATUS(ret));
}
}
int
main(void)
{
int i, fd, ret;
int i, fd;
char spath[1024], dpath[1024];
char *penv[] = {"TESTDIR", "TESTFILE0"};
const char *penv[] = {"TESTDIR", "TESTFILE0"};
struct stat sbuf;
(void) fprintf(stdout, "Verify O_TMPFILE file can be linked.\n");
@@ -37,55 +53,25 @@ main(void)
/*
* Get the environment variable values.
*/
for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
if ((penv[i] = getenv(penv[i])) == NULL) {
(void) fprintf(stderr, "getenv(penv[%d])\n", i);
exit(1);
}
}
for (i = 0; i < ARRAY_SIZE(penv); i++)
if ((penv[i] = getenv(penv[i])) == NULL)
errx(1, "getenv(penv[%d])", i);
fd = open(penv[0], O_RDWR|O_TMPFILE, 0666);
if (fd < 0) {
perror("open");
exit(2);
}
if (fd < 0)
err(2, "open(%s)", penv[0]);
snprintf(spath, 1024, "/proc/self/fd/%d", fd);
snprintf(dpath, 1024, "%s/%s", penv[0], penv[1]);
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) < 0) {
perror("linkat");
close(fd);
exit(3);
}
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) < 0)
err(3, "linkat");
if ((ret = system("sudo -E zpool freeze $TESTPOOL"))) {
if (ret == -1)
perror("system \"zpool freeze\"");
else
fprintf(stderr, "zpool freeze exits with %d\n",
WEXITSTATUS(ret));
exit(4);
}
run("freeze");
close(fd);
if ((ret = system("sudo -E zpool export $TESTPOOL"))) {
if (ret == -1)
perror("system \"zpool export\"");
else
fprintf(stderr, "zpool export exits with %d\n",
WEXITSTATUS(ret));
exit(4);
}
if ((ret = system("sudo -E zpool import $TESTPOOL"))) {
if (ret == -1)
perror("system \"zpool import\"");
else
fprintf(stderr, "zpool import exits with %d\n",
WEXITSTATUS(ret));
exit(4);
}
run("export");
run("import");
if (stat(dpath, &sbuf) < 0) {
perror("stat");
@@ -6,6 +6,7 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <err.h>
/* backward compat in case it's not defined */
#ifndef O_TMPFILE
@@ -28,7 +29,7 @@ main(void)
{
int i, fd;
char spath[1024], dpath[1024];
char *penv[] = {"TESTDIR", "TESTFILE0"};
const char *penv[] = {"TESTDIR", "TESTFILE0"};
struct stat sbuf;
(void) fprintf(stdout, "Verify O_EXCL tmpfile cannot be linked.\n");
@@ -36,33 +37,21 @@ main(void)
/*
* Get the environment variable values.
*/
for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
if ((penv[i] = getenv(penv[i])) == NULL) {
(void) fprintf(stderr, "getenv(penv[%d])\n", i);
exit(1);
}
}
for (i = 0; i < ARRAY_SIZE(penv); i++)
if ((penv[i] = getenv(penv[i])) == NULL)
errx(1, "getenv(penv[%d])", i);
fd = open(penv[0], O_RDWR|O_TMPFILE|O_EXCL, 0666);
if (fd < 0) {
perror("open");
exit(2);
}
if (fd < 0)
err(2, "open(%s)", penv[0]);
snprintf(spath, 1024, "/proc/self/fd/%d", fd);
snprintf(dpath, 1024, "%s/%s", penv[0], penv[1]);
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) == 0) {
fprintf(stderr, "linkat returns successfully\n");
close(fd);
exit(3);
}
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) == 0)
errx(3, "linkat returned successfully\n");
if (stat(dpath, &sbuf) == 0) {
fprintf(stderr, "stat returns successfully\n");
close(fd);
exit(4);
}
close(fd);
if (stat(dpath, &sbuf) == 0)
errx(4, "stat returned successfully\n");
return (0);
}
@@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
/* backward compat in case it's not defined */
#ifndef O_TMPFILE
@@ -50,63 +51,46 @@ test_stat_mode(mode_t mask)
struct stat st, fst;
int i, fd;
char spath[1024], dpath[1024];
char *penv[] = {"TESTDIR", "TESTFILE0"};
const char *penv[] = {"TESTDIR", "TESTFILE0"};
mode_t masked = 0777 & ~mask;
mode_t mode;
/*
* Get the environment variable values.
*/
for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
if ((penv[i] = getenv(penv[i])) == NULL) {
fprintf(stderr, "getenv(penv[%d])\n", i);
exit(1);
}
}
for (i = 0; i < ARRAY_SIZE(penv); i++)
if ((penv[i] = getenv(penv[i])) == NULL)
errx(1, "getenv(penv[%d])", i);
umask(mask);
fd = open(penv[0], O_RDWR|O_TMPFILE, 0777);
if (fd == -1) {
perror("open");
exit(2);
}
if (fd == -1)
err(2, "open(%s)", penv[0]);
if (fstat(fd, &fst) == -1) {
perror("fstat");
close(fd);
exit(3);
}
if (fstat(fd, &fst) == -1)
err(3, "open");
snprintf(spath, sizeof (spath), "/proc/self/fd/%d", fd);
snprintf(dpath, sizeof (dpath), "%s/%s", penv[0], penv[1]);
unlink(dpath);
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) == -1) {
perror("linkat");
close(fd);
exit(4);
}
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) == -1)
err(4, "linkat");
close(fd);
if (stat(dpath, &st) == -1) {
perror("stat");
exit(5);
}
if (stat(dpath, &st) == -1)
err(5, "stat");
unlink(dpath);
/* Verify fstat(2) result */
mode = fst.st_mode & 0777;
if (mode != masked) {
fprintf(stderr, "fstat(2) %o != %o\n", mode, masked);
exit(6);
}
if (mode != masked)
errx(6, "fstat(2) %o != %o\n", mode, masked);
/* Verify stat(2) result */
mode = st.st_mode & 0777;
if (mode != masked) {
fprintf(stderr, "stat(2) %o != %o\n", mode, masked);
exit(7);
}
if (mode != masked)
errx(7, "stat(2) %o != %o\n", mode, masked);
}
int