This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 666d4da3769b91b40c7030190360e33e94f921ad
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Dec 12 16:14:32 2023 -0600
sanlock: reduce warnings
Stop treating the non-null-terminated buffers as strings
to avoid warnings.
---
src/cmd.c | 12 ++++++------
src/delta_lease.c | 2 +-
src/direct.c | 12 ++++++------
src/leader.h | 4 ++--
src/lockspace.c | 9 +++++----
src/main.c | 11 +++++++----
src/paxos_lease.c | 4 ++--
src/resource.c | 4 ++--
src/rindex.c | 2 +-
src/sanlock.h | 12 ++++++------
src/sanlock_internal.h | 4 ++--
11 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
index ae57bf3..64ee409 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -358,7 +358,7 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca, uint32_t cmd)
goto done;
}
- strncpy(cl->owner_name, opt.owner_name, SANLK_NAME_LEN);
+ memcpy(cl->owner_name, opt.owner_name, SANLK_NAME_LEN);
/* data after opt is not used */
/*
@@ -2511,7 +2511,7 @@ static void send_state_daemon(int fd)
int str_len;
memset(&st, 0, sizeof(st));
- strncpy(st.name, our_host_name_global, NAME_ID_SIZE);
+ memcpy(st.name, our_host_name_global, NAME_ID_SIZE);
st.type = SANLK_STATE_DAEMON;
@@ -2534,7 +2534,7 @@ static void send_state_client(int fd, struct client *cl, int ci)
st.type = SANLK_STATE_CLIENT;
st.data32 = cl->pid;
- strncpy(st.name, cl->owner_name, NAME_ID_SIZE);
+ memcpy(st.name, cl->owner_name, NAME_ID_SIZE);
str_len = print_state_client(cl, ci, str);
@@ -2556,7 +2556,7 @@ static void send_state_lockspace(int fd, struct space *sp, const char *list_name
st.type = SANLK_STATE_LOCKSPACE;
st.data64 = sp->host_id;
- strncpy(st.name, sp->space_name, NAME_ID_SIZE);
+ memcpy(st.name, sp->space_name, NAME_ID_SIZE);
str_len = print_state_lockspace(sp, str, list_name);
@@ -2567,7 +2567,7 @@ static void send_state_lockspace(int fd, struct space *sp, const char *list_name
send_all(fd, str, str_len, MSG_NOSIGNAL);
memset(&lockspace, 0, sizeof(struct sanlk_lockspace));
- strncpy(lockspace.name, sp->space_name, NAME_ID_SIZE);
+ memcpy(lockspace.name, sp->space_name, NAME_ID_SIZE);
lockspace.host_id = sp->host_id;
memcpy(&lockspace.host_id_disk, &sp->host_id_disk, sizeof(struct sanlk_disk));
@@ -2590,7 +2590,7 @@ void send_state_resource(int fd, struct resource *r, const char *list_name,
st.type = SANLK_STATE_RESOURCE;
st.data32 = pid;
st.data64 = r->leader.lver;
- strncpy(st.name, r->r.name, NAME_ID_SIZE);
+ memcpy(st.name, r->r.name, NAME_ID_SIZE);
str_len = print_state_resource(r, str, list_name, token_id);
diff --git a/src/delta_lease.c b/src/delta_lease.c
index d36d4e0..4ac63ef 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -900,7 +900,7 @@ int delta_lease_init(struct task *task,
leader.max_hosts = 1;
leader.timestamp = LEASE_FREE;
leader.io_timeout = io_timeout;
- strncpy(leader.space_name, ls->name, NAME_ID_SIZE);
+ memcpy(leader.space_name, ls->name, NAME_ID_SIZE);
leader.checksum = 0; /* set below */
/* make the first record invalid so we can do a single atomic
diff --git a/src/direct.c b/src/direct.c
index f3ea7d1..73861a2 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -728,8 +728,8 @@ int direct_dump(struct task *task, char *dump_path, int force_mode)
if (!lr->owner_id && !lr->owner_generation)
continue;
- strncpy(sname, lr->space_name, NAME_ID_SIZE);
- strncpy(rname, lr->resource_name, NAME_ID_SIZE);
+ strcpy(sname, lr->space_name);
+ strcpy(rname, lr->resource_name);
printf("%08llu %36s %48s %010llu %04llu %04llu",
(unsigned long long)(start_offset + ((sector_nr + i) * sector_size)),
@@ -752,8 +752,8 @@ int direct_dump(struct task *task, char *dump_path, int force_mode)
leader_record_in(lr_end, &lr_in);
lr = &lr_in;
- strncpy(sname, lr->space_name, NAME_ID_SIZE);
- strncpy(rname, lr->resource_name, NAME_ID_SIZE);
+ strcpy(sname, lr->space_name);
+ strcpy(rname, lr->resource_name);
printf("%08llu %36s %48s %010llu %04llu %04llu %llu",
(unsigned long long)(start_offset + (sector_nr * sector_size)),
@@ -804,7 +804,7 @@ int direct_dump(struct task *task, char *dump_path, int force_mode)
rindex_header_in(rh_end, &rh_in);
rh = &rh_in;
- strncpy(sname, rh->lockspace_name, NAME_ID_SIZE);
+ strcpy(sname, rh->lockspace_name);
printf("%08llu %36s rindex_header 0x%x %d %u %llu\n",
(unsigned long long)(start_offset + (sector_nr * sector_size)),
@@ -872,7 +872,7 @@ int direct_next_free(struct task *task, char *path)
sd.offset = atoll(off_str);
}
- strncpy(sd.path, path, SANLK_PATH_LEN);
+ strncpy(sd.path, path, SANLK_PATH_LEN-1);
sd.fd = -1;
rv = open_disk(&sd);
diff --git a/src/leader.h b/src/leader.h
index 7656299..649bcf8 100644
--- a/src/leader.h
+++ b/src/leader.h
@@ -69,8 +69,8 @@ struct leader_record {
uint64_t owner_id; /* host_id of owner */
uint64_t owner_generation;
uint64_t lver;
- char space_name[NAME_ID_SIZE]; /* lockspace for resource */
- char resource_name[NAME_ID_SIZE]; /* resource being locked */
+ char space_name[NAME_ID_SIZE] __attribute__ ((nonstring)); /* lockspace for resource */
+ char resource_name[NAME_ID_SIZE] __attribute__ ((nonstring)); /* resource being locked */
uint64_t timestamp;
uint64_t unused1;
uint32_t checksum;
diff --git a/src/lockspace.c b/src/lockspace.c
index a874148..da51af0 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -449,7 +449,7 @@ void check_other_leases(struct space *sp, char *buf)
(unsigned long long)leader->owner_generation,
(unsigned long long)leader->timestamp,
leader->resource_name);
- strncpy(hs->owner_name, leader->resource_name, NAME_ID_SIZE);
+ memcpy(hs->owner_name, leader->resource_name, NAME_ID_SIZE);
}
if (hs->owner_id == leader->owner_id &&
@@ -469,7 +469,7 @@ void check_other_leases(struct space *sp, char *buf)
if (!hs->lease_bad) {
hs->owner_id = leader->owner_id;
hs->owner_generation = leader->owner_generation;
- strncpy(hs->owner_name, leader->resource_name, NAME_ID_SIZE);
+ memcpy(hs->owner_name, leader->resource_name, NAME_ID_SIZE);
hs->io_timeout = leader->io_timeout;
}
@@ -1057,9 +1057,10 @@ int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct
int i;
if (!ls->name[0] || !ls->host_id || !ls->host_id_disk.path[0]) {
- log_error("add_lockspace bad args id %llu name %zu path %zu",
+ log_error("add_lockspace bad args host_id %llu name %s path %s",
(unsigned long long)ls->host_id,
- strlen(ls->name), strlen(ls->host_id_disk.path));
+ ls->name[0] ? "set" : "empty",
+ ls->host_id_disk.path[0] ? "set" : "empty");
return -EINVAL;
}
diff --git a/src/main.c b/src/main.c
index 4e7f3c0..96ad50a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1904,8 +1904,11 @@ static int parse_arg_rentry(char *str)
com.rentry.offset = offnum;
}
- if (name)
- strncpy(com.rentry.name, name, SANLK_NAME_LEN);
+ if (name) {
+ char tmps[SANLK_NAME_LEN+1] = { 0 };
+ strncpy(tmps, name, SANLK_NAME_LEN);
+ memcpy(com.rentry.name, tmps, SANLK_NAME_LEN);
+ }
return 0;
}
@@ -2886,7 +2889,7 @@ static void read_config_file(void)
} else if (!strcmp(str, "our_host_name")) {
memset(str, 0, sizeof(str));
get_val_str(line, str);
- strncpy(com.our_host_name, str, NAME_ID_SIZE);
+ memcpy(com.our_host_name, str, NAME_ID_SIZE);
} else if (!strcmp(str, "renewal_read_extend_sec")) {
/* zero is a valid setting so we need the _set field to say it's set */
@@ -3319,7 +3322,7 @@ static int do_client(void)
if (!res_ls)
break;
memset(res_ls, 0, sizeof(struct sanlk_resource));
- strcpy(res_ls->lockspace_name, com.lockspace.name);
+ memcpy(res_ls->lockspace_name, com.lockspace.name, SANLK_NAME_LEN);
com.res_args[0] = res_ls;
com.res_count = 1;
}
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index ce265e7..179d8e7 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -2467,8 +2467,8 @@ int paxos_lease_init(struct task *task,
leader.sector_size = sector_size;
leader.num_hosts = num_hosts;
leader.max_hosts = max_hosts;
- strncpy(leader.space_name, token->r.lockspace_name, NAME_ID_SIZE);
- strncpy(leader.resource_name, token->r.name, NAME_ID_SIZE);
+ memcpy(leader.space_name, token->r.lockspace_name, NAME_ID_SIZE);
+ memcpy(leader.resource_name, token->r.name, NAME_ID_SIZE);
leader.checksum = 0; /* set after leader_record_out */
memset(&rr, 0, sizeof(rr));
diff --git a/src/resource.c b/src/resource.c
index 0235b53..c1c49f9 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -107,9 +107,9 @@ static struct resource *get_free_resource(struct token *token, int *token_matche
/* find a previous r that matches token */
list_for_each_entry(r, &resources_free, list) {
- if (strcmp(r->r.lockspace_name, token->r.lockspace_name))
+ if (memcmp(r->r.lockspace_name, token->r.lockspace_name, SANLK_NAME_LEN))
continue;
- if (strcmp(r->r.name, token->r.name))
+ if (memcmp(r->r.name, token->r.name, SANLK_NAME_LEN))
continue;
if (r->r.num_disks != token->r.num_disks)
continue;
diff --git a/src/rindex.c b/src/rindex.c
index 9ef02da..0ac503e 100644
--- a/src/rindex.c
+++ b/src/rindex.c
@@ -437,7 +437,7 @@ int rindex_format(struct task *task, struct sanlk_rindex *ri)
rh.sector_size = sector_size;
rh.max_resources = max_resources;
rh.rx_offset = rx.disk->offset;
- strncpy(rh.lockspace_name, rx.ri->lockspace_name, NAME_ID_SIZE);
+ memcpy(rh.lockspace_name, rx.ri->lockspace_name, NAME_ID_SIZE);
memset(&rh_end, 0, sizeof(struct rindex_header));
rindex_header_out(&rh, &rh_end);
diff --git a/src/sanlock.h b/src/sanlock.h
index 5999630..978aac7 100644
--- a/src/sanlock.h
+++ b/src/sanlock.h
@@ -96,8 +96,8 @@ struct sanlk_disk {
#define SANLK_RES_SECTOR4K 0x00000200
struct sanlk_resource {
- char lockspace_name[SANLK_NAME_LEN]; /* terminating \0 not required */
- char name[SANLK_NAME_LEN]; /* terminating \0 not required */
+ char lockspace_name[SANLK_NAME_LEN] __attribute__ ((nonstring)); /* terminating \0 not required */
+ char name[SANLK_NAME_LEN] __attribute__ ((nonstring)); /* terminating \0 not required */
uint64_t lver; /* use with SANLK_RES_LVER */
uint64_t data64; /* per-resource command-specific data */
uint32_t data32; /* per-resource command-specific data */
@@ -120,12 +120,12 @@ struct sanlk_rindex {
uint32_t flags; /* SANLK_RIF_ */
uint32_t max_resources; /* the max res structs that will follow rindex */
uint64_t unused;
- char lockspace_name[SANLK_NAME_LEN]; /* terminating \0 not required */
+ char lockspace_name[SANLK_NAME_LEN] __attribute__ ((nonstring)); /* terminating \0 not required */
struct sanlk_disk disk; /* location of rindex */
};
struct sanlk_rentry {
- char name[SANLK_NAME_LEN]; /* terminating \0 not required */
+ char name[SANLK_NAME_LEN] __attribute__ ((nonstring)); /* terminating \0 not required */
uint64_t offset;
uint32_t flags;
uint32_t unused;
@@ -135,7 +135,7 @@ struct sanlk_rentry {
that requires the extra work of segmenting it by resource name) */
struct sanlk_options {
- char owner_name[SANLK_NAME_LEN]; /* optional user friendly name */
+ char owner_name[SANLK_NAME_LEN] __attribute__ ((nonstring)); /* optional user friendly name */
uint32_t flags;
uint32_t len; /* unused and ignored */
/* followed by len bytes (unused and ignored) */
@@ -154,7 +154,7 @@ struct sanlk_options {
#define SANLK_LSF_SECTOR4K 0x00000200
struct sanlk_lockspace {
- char name[SANLK_NAME_LEN];
+ char name[SANLK_NAME_LEN] __attribute__ ((nonstring));
uint64_t host_id;
uint32_t flags; /* SANLK_LSF_ */
struct sanlk_disk host_id_disk;
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index d8c027f..3e06e4f 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -179,7 +179,7 @@ struct host_status {
uint64_t set_bit_time;
uint16_t io_timeout;
uint16_t lease_bad;
- char owner_name[NAME_ID_SIZE];
+ char owner_name[NAME_ID_SIZE] __attribute__ ((nonstring));
};
struct renewal_history {
@@ -198,7 +198,7 @@ struct renewal_history {
struct space {
struct list_head list;
- char space_name[NAME_ID_SIZE];
+ char space_name[NAME_ID_SIZE] __attribute__ ((nonstring));
uint32_t space_id; /* used to refer to this space instance in log messages */
uint64_t host_id;
uint64_t host_generation;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.