maint: port to Fedora 33

Fedora 33 uses GCC 10.2.1, which is a bit pickier.
* configure.ac: Do not use -Wsystem-headers, as this
runs afoul of netdb.h on Fedora 33.
* gnulib.modules: Add ‘attribute’.
* lib/wordsplit.c (wsnode_new): Return the newly allocated
pointer instead of a boolean, to pacify GCC 10.2.1 which otherwise
complains about use of possibly-null pointers.  All uses changed.
* src/buffer.c (try_new_volume): Don’t assume find_next_block succeeds.
(_write_volume_label): Pacify GCC 10.2.1 with an ‘assume’, since
LABEL must be nonnull here.
* src/common.h (FALLTHROUGH): Remove; now in attribute.h.
Include attribute.h, for ATTRIBUTE_NONNULL.
* src/misc.c (assign_string_or_null): New function,
taking over the old role of assign_string.
(assign_string): Assume VALUE is non-null.
(assign_null): New function, taking over the old
role of assign_string when its VALUE was nonnull.
All callers of assign_string changed to use these functions.
(assign_string_n): Clear *STRING if VALUE is null,
to fix a potential double-free.
This commit is contained in:
Paul Eggert
2021-02-27 16:41:12 -08:00
parent fa6d317bc7
commit 8378991cba
7 changed files with 124 additions and 100 deletions

View File

@@ -162,6 +162,7 @@ if test "$gl_gcc_warnings" = yes; then
nw="$nw -Winline" # It's OK to not inline.
nw="$nw -Wstrict-overflow" # It's OK to optimize strictly.
nw="$nw -Wsuggest-attribute=pure" # Too many warnings for now.
nw="$nw -Wsystem-headers" # Don't let system headers trigger warnings
nw="$nw -Wstack-protector"
gl_MANYWARN_ALL_GCC([ws])

View File

@@ -23,6 +23,7 @@ areadlinkat-with-size
argmatch
argp
argp-version-etc
attribute
backupfile
closeout
configmake

View File

@@ -424,14 +424,13 @@ wsnode_len (struct wordsplit_node *p)
return p->v.segm.end - p->v.segm.beg;
}
static int
wsnode_new (struct wordsplit *wsp, struct wordsplit_node **pnode)
static struct wordsplit_node *
wsnode_new (struct wordsplit *wsp)
{
struct wordsplit_node *node = calloc (1, sizeof (*node));
if (!node)
return _wsplt_nomem (wsp);
*pnode = node;
return 0;
_wsplt_nomem (wsp);
return node;
}
static void
@@ -527,14 +526,11 @@ wsnode_insert (struct wordsplit *wsp, struct wordsplit_node *node,
static int
wordsplit_add_segm (struct wordsplit *wsp, size_t beg, size_t end, int flg)
{
struct wordsplit_node *node;
int rc;
if (end == beg && !(flg & _WSNF_EMPTYOK))
return 0;
rc = wsnode_new (wsp, &node);
if (rc)
return rc;
struct wordsplit_node *node = wsnode_new (wsp);
if (!node)
return 1;
node->flags = flg & ~(_WSNF_WORD | _WSNF_EMPTYOK);
node->v.segm.beg = beg;
node->v.segm.end = end;
@@ -900,11 +896,11 @@ node_split_prefix (struct wordsplit *wsp,
struct wordsplit_node *node,
size_t beg, size_t len, int flg)
{
struct wordsplit_node *newnode;
if (len == 0)
return 0;
if (wsnode_new (wsp, &newnode))
struct wordsplit_node *newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
if (node->flags & _WSNF_WORD)
@@ -1195,7 +1191,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
}
else
{
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1357,7 +1354,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
{
if (flg & _WSNF_QUOTE)
{
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
{
free (value);
return 1;
@@ -1371,7 +1369,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
{
free (value);
/* Empty string is a special case */
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1404,7 +1403,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
{
size_t size = *pend - start + 1;
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1417,7 +1417,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
}
else
{
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1585,7 +1586,8 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
{
if (flg & _WSNF_QUOTE)
{
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1596,7 +1598,8 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
{
free (value);
/* Empty string is a special case */
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1627,7 +1630,8 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
}
else
{
if (wsnode_new (wsp, &newnode))
newnode = wsnode_new (wsp);
if (!newnode)
return 1;
wsnode_insert (wsp, newnode, *ptail, 0);
*ptail = newnode;
@@ -1855,10 +1859,10 @@ wordsplit_pathexpand (struct wordsplit *wsp)
prev = p;
for (i = 0; i < g.gl_pathc; i++)
{
struct wordsplit_node *newnode;
struct wordsplit_node *newnode = wsnode_new (wsp);
char *newstr;
if (wsnode_new (wsp, &newnode))
if (!newnode)
return 1;
newstr = strdup (g.gl_pathv[i]);
if (!newstr)
@@ -2559,4 +2563,3 @@ wordsplit_perror (struct wordsplit *wsp)
wsp->ws_error ("%s", wordsplit_strerror (wsp));
}
}

View File

@@ -28,6 +28,7 @@
#include <fnmatch.h>
#include <human.h>
#include <quotearg.h>
#include <verify.h>
#include "common.h"
#include <rmt.h>
@@ -1325,8 +1326,8 @@ new_volume (enum access_mode mode)
if (verify_option)
verify_volume ();
assign_string (&volume_label, NULL);
assign_string (&continued_file_name, NULL);
assign_null (&volume_label);
assign_null (&continued_file_name);
continued_file_size = continued_file_offset = 0;
current_block = record_start;
@@ -1505,7 +1506,7 @@ try_new_volume (void)
ASSIGN_STRING_N (&volume_label, current_header->header.name);
set_next_block_after (header);
header = find_next_block ();
if (header->header.typeflag != GNUTYPE_MULTIVOL)
if (! (header && header->header.typeflag == GNUTYPE_MULTIVOL))
break;
FALLTHROUGH;
case GNUTYPE_MULTIVOL:
@@ -1688,6 +1689,7 @@ _write_volume_label (const char *str)
{
union block *label = find_next_block ();
assume (label);
memset (label, 0, BLOCKSIZE);
strcpy (label->header.name, str);

View File

@@ -43,18 +43,13 @@
# define GLOBAL extern
#endif
#if 7 <= __GNUC__
# define FALLTHROUGH __attribute__ ((__fallthrough__))
#else
# define FALLTHROUGH ((void) 0)
#endif
#define TAREXIT_SUCCESS PAXEXIT_SUCCESS
#define TAREXIT_DIFFERS PAXEXIT_DIFFERS
#define TAREXIT_FAILURE PAXEXIT_FAILURE
#include "arith.h"
#include <attribute.h>
#include <backupfile.h>
#include <exclude.h>
#include <full-write.h>
@@ -633,7 +628,10 @@ void skip_member (void);
#define max(a, b) ((a) < (b) ? (b) : (a))
char const *quote_n_colon (int n, char const *arg);
void assign_string (char **dest, const char *src);
void assign_string_or_null (char **dest, const char *src)
ATTRIBUTE_NONNULL ((1));
void assign_string (char **dest, const char *src) ATTRIBUTE_NONNULL ((1, 2));
void assign_null (char **dest) ATTRIBUTE_NONNULL ((1));
void assign_string_n (char **string, const char *value, size_t n);
#define ASSIGN_STRING_N(s,v) assign_string_n (s, v, sizeof (v))
int unquote_string (char *str);

View File

@@ -520,7 +520,7 @@ delay_set_stat (char const *file_name, struct tar_stat_info const *st,
data->change_dir = chdir_current;
data->cntx_name = NULL;
if (st)
assign_string (&data->cntx_name, st->cntx_name);
assign_string_or_null (&data->cntx_name, st->cntx_name);
if (st && st->acls_a_ptr)
{
data->acls_a_ptr = xmemdup (st->acls_a_ptr, st->acls_a_len + 1);
@@ -1442,7 +1442,7 @@ create_placeholder_file (char *file_name, bool is_symlink, bool *interdir_made,
p->sources->next = 0;
strcpy (p->sources->string, file_name);
p->cntx_name = NULL;
assign_string (&p->cntx_name, current_stat_info.cntx_name);
assign_string_or_null (&p->cntx_name, current_stat_info.cntx_name);
p->acls_a_ptr = NULL;
p->acls_a_len = 0;
p->acls_d_ptr = NULL;

View File

@@ -42,11 +42,28 @@ quote_n_colon (int n, char const *arg)
/* Assign STRING to a copy of VALUE if not zero, or to zero. If
STRING was nonzero, it is freed first. */
void
assign_string_or_null (char **string, const char *value)
{
if (value)
assign_string (string, value);
else
assign_null (string);
}
void
assign_string (char **string, const char *value)
{
free (*string);
*string = value ? xstrdup (value) : 0;
*string = xstrdup (value);
}
void
assign_null (char **string)
{
char *old = *string;
*string = NULL;
free (old);
}
void
@@ -61,6 +78,8 @@ assign_string_n (char **string, const char *value, size_t n)
p[l] = 0;
*string = p;
}
else
*string = NULL;
}
#if 0
@@ -715,7 +734,7 @@ maybe_backup_file (const char *file_name, bool this_is_the_archive)
possible, real problems are unlikely. Doing any better would require a
convention, GNU-wide, for all programs doing backups. */
assign_string (&after_backup_name, 0);
assign_null (&after_backup_name);
/* Check if we really need to backup the file. */
@@ -758,7 +777,7 @@ maybe_backup_file (const char *file_name, bool this_is_the_archive)
ERROR ((0, e, _("%s: Cannot rename to %s"),
quotearg_colon (before_backup_name),
quote_n (1, after_backup_name)));
assign_string (&after_backup_name, 0);
assign_null (&after_backup_name);
return false;
}
}
@@ -782,7 +801,7 @@ undo_last_backup (void)
fprintf (stdlis, _("Renaming %s back to %s\n"),
quote_n (0, after_backup_name),
quote_n (1, before_backup_name));
assign_string (&after_backup_name, 0);
assign_null (&after_backup_name);
}
}