Skip to content

Commit

Permalink
Cast away the return value of g_strlcpy() and g_strlcat().
Browse files Browse the repository at this point in the history
Most of the time, the return value tells us nothing useful, as we've
already decided that we're perfectly willing to live with string
truncation.  Hopefully this keeps Coverity from whining that those
routines could return an error code (NARRATOR: They don't) and thus that
we're ignoring the possibility of failure (as indicated, we've already
decided that we can live with string truncation, so truncation is *NOT*
a failure).
  • Loading branch information
guyharris committed Apr 30, 2021
1 parent 0914739 commit 57a1514
Show file tree
Hide file tree
Showing 131 changed files with 599 additions and 599 deletions.
6 changes: 3 additions & 3 deletions capinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,9 @@ main(int argc, char *argv[])

for (opt = optind; opt < argc; opt++) {

g_strlcpy(file_sha256, "<unknown>", HASH_STR_SIZE);
g_strlcpy(file_rmd160, "<unknown>", HASH_STR_SIZE);
g_strlcpy(file_sha1, "<unknown>", HASH_STR_SIZE);
(void) g_strlcpy(file_sha256, "<unknown>", HASH_STR_SIZE);
(void) g_strlcpy(file_rmd160, "<unknown>", HASH_STR_SIZE);
(void) g_strlcpy(file_sha1, "<unknown>", HASH_STR_SIZE);

if (cap_file_hashes) {
fh = ws_fopen(argv[opt], "rb");
Expand Down
12 changes: 6 additions & 6 deletions capture/capture-pcap-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ if_info_get(const char *name)
* Get the description for the interface.
*/
memset(&ifrdesc, 0, sizeof ifrdesc);
g_strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name);
(void) g_strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s >= 0) {
#ifdef __FreeBSD__
Expand Down Expand Up @@ -1138,7 +1138,7 @@ is_linux_bonding_device(const char *ifname)
return FALSE;

memset(&ifr, 0, sizeof ifr);
g_strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
(void) g_strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
memset(&ifb, 0, sizeof ifb);
ifr.ifr_data = (caddr_t)&ifb;
#if defined(SIOCBONDINFOQUERY)
Expand Down Expand Up @@ -1329,7 +1329,7 @@ open_capture_device_pcap_create(
*/
if (status == PCAP_ERROR) {
*open_err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
g_strlcpy(*open_err_str, pcap_geterr(pcap_h),
(void) g_strlcpy(*open_err_str, pcap_geterr(pcap_h),
sizeof *open_err_str);
pcap_close(pcap_h);
return NULL;
Expand All @@ -1353,14 +1353,14 @@ open_capture_device_pcap_create(
/* Failed to activate, set to NULL */
if (status == PCAP_ERROR) {
*open_err = CAP_DEVICE_OPEN_ERR_GENERIC;
g_strlcpy(*open_err_str, pcap_geterr(pcap_h),
(void) g_strlcpy(*open_err_str, pcap_geterr(pcap_h),
sizeof *open_err_str);
} else {
if (status == PCAP_ERROR_PERM_DENIED)
*open_err = CAP_DEVICE_OPEN_ERR_PERMISSIONS;
else
*open_err = CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS;
g_strlcpy(*open_err_str, pcap_statustostr(status),
(void) g_strlcpy(*open_err_str, pcap_statustostr(status),
sizeof *open_err_str);
}
pcap_close(pcap_h);
Expand Down Expand Up @@ -1592,7 +1592,7 @@ open_capture_device(capture_options *capture_opts,
* no error message is filled in on a
* failure to open an rpcap: URL.
*/
g_strlcpy(*open_err_str,
(void) g_strlcpy(*open_err_str,
"Unknown error (pcap bug; actual error cause not reported)",
sizeof *open_err_str);
}
Expand Down
4 changes: 2 additions & 2 deletions capture/ws80211_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static int get_freq_wext(const char *ifname)
if (fd == -1)
return -1;

g_strlcpy(wrq.name1, ifname, IFNAMSIZ);
(void) g_strlcpy(wrq.name1, ifname, IFNAMSIZ);
/* SIOCGIWFREQ */
if (ioctl(fd, 0x8B05, &wrq) == 0) {
if (wrq.e == 6)
Expand Down Expand Up @@ -699,7 +699,7 @@ static int ws80211_iface_up(const char *ifname)
if (sock == -1)
return -1;

g_strlcpy(ifreq.ifr_name, ifname, sizeof(ifreq.ifr_name));
(void) g_strlcpy(ifreq.ifr_name, ifname, sizeof(ifreq.ifr_name));

if (ioctl(sock, SIOCGIFFLAGS, &ifreq))
goto out_err;
Expand Down
2 changes: 1 addition & 1 deletion editcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ main(int argc, char *argv[])

if (err_type < ERR_WT_FMT) {
if ((unsigned int)i < caplen - 2)
g_strlcpy((char*) &buf[i], "%s", 2);
(void) g_strlcpy((char*) &buf[i], "%s", 2);
err_type = ERR_WT_TOTAL;
} else {
err_type -= ERR_WT_FMT;
Expand Down
44 changes: 22 additions & 22 deletions epan/addr_resolv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ static void
fill_dummy_ip6(hashipv6_t* volatile tp)
{
/* Overwrite if we get async DNS reply */
g_strlcpy(tp->name, tp->ip6, MAXNAMELEN);
(void) g_strlcpy(tp->name, tp->ip6, MAXNAMELEN);
}

static void
Expand Down Expand Up @@ -1457,14 +1457,14 @@ parse_ether_line(char *line, ether_t *eth, unsigned int *mask,
if ((cp = strtok(NULL, " \t")) == NULL)
return -1;

g_strlcpy(eth->name, cp, MAXNAMELEN);
(void) g_strlcpy(eth->name, cp, MAXNAMELEN);

if ((cp = strtok(NULL, "\t")) != NULL)
{
g_strlcpy(eth->longname, cp, MAXNAMELEN);
(void) g_strlcpy(eth->longname, cp, MAXNAMELEN);
} else {
/* Make the long name the short name */
g_strlcpy(eth->longname, eth->name, MAXNAMELEN);
(void) g_strlcpy(eth->longname, eth->name, MAXNAMELEN);
}

return 0;
Expand Down Expand Up @@ -1550,13 +1550,13 @@ manuf_hash_new_entry(const guint8 *addr, char* name, char* longname)

memcpy(manuf_value->addr, addr, 3);
if (name != NULL) {
g_strlcpy(manuf_value->resolved_name, name, MAXNAMELEN);
(void) g_strlcpy(manuf_value->resolved_name, name, MAXNAMELEN);
manuf_value->status = HASHETHER_STATUS_RESOLVED_NAME;
if (longname != NULL) {
g_strlcpy(manuf_value->resolved_longname, longname, MAXNAMELEN);
(void) g_strlcpy(manuf_value->resolved_longname, longname, MAXNAMELEN);
}
else {
g_strlcpy(manuf_value->resolved_longname, name, MAXNAMELEN);
(void) g_strlcpy(manuf_value->resolved_longname, name, MAXNAMELEN);
}
}
else {
Expand Down Expand Up @@ -1774,7 +1774,7 @@ eth_addr_resolve(hashether_t *tp) {
const guint8 *addr = tp->addr;

if ( (eth = get_ethbyaddr(addr)) != NULL) {
g_strlcpy(tp->resolved_name, eth->name, MAXNAMELEN);
(void) g_strlcpy(tp->resolved_name, eth->name, MAXNAMELEN);
tp->status = HASHETHER_STATUS_RESOLVED_NAME;
return tp;
} else {
Expand Down Expand Up @@ -1907,7 +1907,7 @@ add_eth_name(const guint8 *addr, const gchar *name)
}

if (strcmp(tp->resolved_name, name) != 0) {
g_strlcpy(tp->resolved_name, name, MAXNAMELEN);
(void) g_strlcpy(tp->resolved_name, name, MAXNAMELEN);
tp->status = HASHETHER_STATUS_RESOLVED_NAME;
new_resolved_objects = TRUE;
}
Expand Down Expand Up @@ -1981,7 +1981,7 @@ parse_ipxnets_line(char *line, ipxnet_t *ipxnet)
ipxnet->addr = (a0 << 24) | (a1 << 16) | (a2 << 8) | a3;
}

g_strlcpy(ipxnet->name, cp, MAXNAMELEN);
(void) g_strlcpy(ipxnet->name, cp, MAXNAMELEN);

return 0;

Expand Down Expand Up @@ -2111,7 +2111,7 @@ ipxnet_name_lookup(wmem_allocator_t *allocator, const guint addr)
g_snprintf(tp->name, MAXNAMELEN, "%X", addr);

} else {
g_strlcpy(tp->name, ipxnet->name, MAXNAMELEN);
(void) g_strlcpy(tp->name, ipxnet->name, MAXNAMELEN);
}

return wmem_strdup(allocator, tp->name);
Expand Down Expand Up @@ -2141,7 +2141,7 @@ parse_vlan_line(char *line, vlan_t *vlan)
if ((cp = strtok(NULL, "\t\n")) == NULL)
return -1;

g_strlcpy(vlan->name, cp, MAXVLANNAMELEN);
(void) g_strlcpy(vlan->name, cp, MAXVLANNAMELEN);

return 0;

Expand Down Expand Up @@ -2255,7 +2255,7 @@ vlan_name_lookup(const guint id)
g_snprintf(tp->name, MAXVLANNAMELEN, "<%u>", id);

} else {
g_strlcpy(tp->name, vlan->name, MAXVLANNAMELEN);
(void) g_strlcpy(tp->name, vlan->name, MAXVLANNAMELEN);
}

return tp->name;
Expand Down Expand Up @@ -2363,7 +2363,7 @@ add_ip_name_from_string (const char *addr, const char *name)
if (resolved_entry)
{
// If we found a previous matching key (IP address), then just update the value (custom hostname);
g_strlcpy(resolved_entry->name, name, MAXNAMELEN);
(void) g_strlcpy(resolved_entry->name, name, MAXNAMELEN);
}
else
{
Expand All @@ -2372,7 +2372,7 @@ add_ip_name_from_string (const char *addr, const char *name)
memcpy(addr_key, &host_addr.ip6_addr, sizeof(ws_in6_addr));

resolved_entry = wmem_new(wmem_epan_scope(), resolved_name_t);
g_strlcpy(resolved_entry->name, name, MAXNAMELEN);
(void) g_strlcpy(resolved_entry->name, name, MAXNAMELEN);

wmem_map_insert(manually_resolved_ipv6_list, addr_key, resolved_entry);
}
Expand All @@ -2381,13 +2381,13 @@ add_ip_name_from_string (const char *addr, const char *name)
if (resolved_entry)
{
// If we found a previous matching key (IP address), then just update the value (custom hostname);
g_strlcpy(resolved_entry->name, name, MAXNAMELEN);
(void) g_strlcpy(resolved_entry->name, name, MAXNAMELEN);
}
else
{
// Add a new mapping entry, if this IP address isn't already in the list.
resolved_entry = wmem_new(wmem_epan_scope(), resolved_name_t);
g_strlcpy(resolved_entry->name, name, MAXNAMELEN);
(void) g_strlcpy(resolved_entry->name, name, MAXNAMELEN);

wmem_map_insert(manually_resolved_ipv4_list, GUINT_TO_POINTER(host_addr.ip4_addr), resolved_entry);
}
Expand Down Expand Up @@ -2610,7 +2610,7 @@ subnet_entry_set(guint32 subnet_addr, const guint8 mask_length, const gchar* nam

tp->next = NULL;
tp->addr = subnet_addr;
g_strlcpy(tp->name, name, MAXNAMELEN); /* This is longer than subnet names can actually be */
(void) g_strlcpy(tp->name, name, MAXNAMELEN); /* This is longer than subnet names can actually be */
have_subnet_entry = TRUE;
}

Expand Down Expand Up @@ -2686,7 +2686,7 @@ void fill_unresolved_ss7pc(const gchar * pc_addr, const guint8 ni, const guint32
{
hashss7pc_t *tp = host_lookup_ss7pc(ni, pc);

g_strlcpy(tp->pc_addr, pc_addr, MAXNAMELEN);
(void) g_strlcpy(tp->pc_addr, pc_addr, MAXNAMELEN);
}

const gchar *
Expand Down Expand Up @@ -2725,7 +2725,7 @@ add_ss7pc_name(const guint8 ni, guint32 pc, const gchar *name)
}

if (g_ascii_strcasecmp(tp->name, name)) {
g_strlcpy(tp->name, name, MAXNAMELEN);
(void) g_strlcpy(tp->name, name, MAXNAMELEN);
}
}

Expand Down Expand Up @@ -3032,7 +3032,7 @@ add_ipv4_name(const guint addr, const gchar *name)
}

if (g_ascii_strcasecmp(tp->name, name)) {
g_strlcpy(tp->name, name, MAXNAMELEN);
(void) g_strlcpy(tp->name, name, MAXNAMELEN);
new_resolved_objects = TRUE;
}
tp->flags |= TRIED_RESOLVE_ADDRESS|NAME_RESOLVED;
Expand Down Expand Up @@ -3062,7 +3062,7 @@ add_ipv6_name(const ws_in6_addr *addrp, const gchar *name)
}

if (g_ascii_strcasecmp(tp->name, name)) {
g_strlcpy(tp->name, name, MAXNAMELEN);
(void) g_strlcpy(tp->name, name, MAXNAMELEN);
new_resolved_objects = TRUE;
}
tp->flags |= TRIED_RESOLVE_ADDRESS|NAME_RESOLVED;
Expand Down
2 changes: 1 addition & 1 deletion epan/address_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static int fcwwn_name_res_len(void)
******************************************************************************/
static int stringz_addr_to_str(const address* addr, gchar *buf, int buf_len)
{
g_strlcpy(buf, (const gchar *)addr->data, buf_len);
(void) g_strlcpy(buf, (const gchar *)addr->data, buf_len);
return (int)(strlen(buf)+1);
}

Expand Down
Loading

0 comments on commit 57a1514

Please sign in to comment.