Skip to content

Commit 8f15111

Browse files
committed
Make gcc die on init overflow of an array.
- Use -pedantic-errors with gcc to make an array-init fatal. - Fix all the extra warnings that gcc outputs due to this option. - Also add -Wno-pedantic to gcc if we're using the internal popt code (since it has lots of pedantic issues).
1 parent acca9d4 commit 8f15111

File tree

7 files changed

+33
-14
lines changed

7 files changed

+33
-14
lines changed

configure.ac

+8-2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ fi
116116
# I don't want our version too far out of sync.
117117
CFLAGS="$CFLAGS -DHAVE_CONFIG_H"
118118

119-
# If GCC, turn on warnings.
119+
# If GCC, turn on warnings and turn pedantic warnings into errors to ensure an array-init overflow is an error.
120120
if test x"$GCC" = x"yes"; then
121-
CFLAGS="$CFLAGS -Wall -W"
121+
CFLAGS="$CFLAGS -Wall -W -pedantic-errors"
122122
fi
123123

124124
AC_ARG_WITH(included-popt,
@@ -1046,6 +1046,12 @@ elif test x"$ac_cv_header_popt_h" != x"yes"; then
10461046
with_included_popt=yes
10471047
fi
10481048

1049+
if test x"$with_included_popt" = x"yes" -a x"$GCC" = x"yes"; then
1050+
# Our internal popt code cannot be compiled with pedantic warnings as errors, so turn off
1051+
# pedantic warnings. This does not affect the array-init overflow as an error, though.
1052+
CFLAGS="$CFLAGS -Wno-pedantic"
1053+
fi
1054+
10491055
AC_MSG_CHECKING([whether to use included libpopt])
10501056
if test x"$with_included_popt" = x"yes"; then
10511057
AC_MSG_RESULT($srcdir/popt)

generator.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ static int remember_delete(struct file_struct *file, const char *fname, int flag
182182
static int read_delay_line(char *buf, int *flags_p)
183183
{
184184
static int read_pos = 0;
185-
int j, len, mode;
185+
unsigned int mode;
186+
int j, len;
186187
char *bp, *past_space;
187188

188189
while (1) {

loadparm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static BOOL do_parameter(char *parmname, char *parmvalue)
437437
break;
438438

439439
case P_OCTAL:
440-
sscanf(parmvalue, "%o", (int *)parm_ptr);
440+
sscanf(parmvalue, "%o", (unsigned int *)parm_ptr);
441441
break;
442442

443443
case P_PATH:

log.c

+17-7
Original file line numberDiff line numberDiff line change
@@ -838,14 +838,24 @@ void maybe_log_item(struct file_struct *file, int iflags, int itemizing, const c
838838

839839
void log_delete(const char *fname, int mode)
840840
{
841-
static struct {
842-
union file_extras ex[4]; /* just in case... */
843-
struct file_struct file;
844-
} x; /* Zero-initialized due to static declaration. */
841+
static struct file_struct *file = NULL;
845842
int len = strlen(fname);
846843
const char *fmt;
847844

848-
x.file.mode = mode;
845+
if (!file) {
846+
int extra_len = (file_extra_cnt + 2) * EXTRA_LEN;
847+
char *bp;
848+
#if EXTRA_ROUNDING > 0
849+
if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
850+
extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN;
851+
#endif
852+
853+
bp = new_array0(char, FILE_STRUCT_LEN + extra_len + 1);
854+
bp += extra_len;
855+
file = (struct file_struct *)bp;
856+
}
857+
858+
file->mode = mode;
849859

850860
if (am_server && protocol_version >= 29 && len < MAXPATHLEN) {
851861
if (S_ISDIR(mode))
@@ -855,14 +865,14 @@ void log_delete(const char *fname, int mode)
855865
;
856866
else {
857867
fmt = stdout_format_has_o_or_i ? stdout_format : "deleting %n";
858-
log_formatted(FCLIENT, fmt, "del.", &x.file, fname, ITEM_DELETED, NULL);
868+
log_formatted(FCLIENT, fmt, "del.", file, fname, ITEM_DELETED, NULL);
859869
}
860870

861871
if (!logfile_name || dry_run || !logfile_format)
862872
return;
863873

864874
fmt = logfile_format_has_o_or_i ? logfile_format : "deleting %n";
865-
log_formatted(FLOG, fmt, "del.", &x.file, fname, ITEM_DELETED, NULL);
875+
log_formatted(FLOG, fmt, "del.", file, fname, ITEM_DELETED, NULL);
866876
}
867877

868878
/*

tls.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ int nsec_times = 0;
6060

6161
static int stat_xattr(const char *fname, STRUCT_STAT *fst)
6262
{
63-
int mode, rdev_major, rdev_minor, uid, gid, len;
63+
unsigned int mode;
64+
int rdev_major, rdev_minor, uid, gid, len;
6465
char buf[256];
6566

6667
if (am_root >= 0 || IS_DEVICE(fst->st_mode) || IS_SPECIAL(fst->st_mode))

token.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ static int32 recv_deflated_token(int f, char **data)
570570
rx_strm.avail_in = 4;
571571
rx_strm.next_in = (Bytef *)cbuf;
572572
cbuf[0] = cbuf[1] = 0;
573-
cbuf[2] = cbuf[3] = 0xff;
573+
cbuf[2] = cbuf[3] = (char)0xff;
574574
inflate(&rx_strm, Z_SYNC_FLUSH);
575575
recv_state = r_idle;
576576
}

xattrs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,8 @@ int del_def_xattr_acl(const char *fname)
11181118

11191119
int get_stat_xattr(const char *fname, int fd, STRUCT_STAT *fst, STRUCT_STAT *xst)
11201120
{
1121-
int mode, rdev_major, rdev_minor, uid, gid, len;
1121+
unsigned int mode;
1122+
int rdev_major, rdev_minor, uid, gid, len;
11221123
char buf[256];
11231124

11241125
if (am_root >= 0 || IS_DEVICE(fst->st_mode) || IS_SPECIAL(fst->st_mode))

0 commit comments

Comments
 (0)