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
@@ -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