From be5277591fe2a142ea3120ddbc16746ea846bc05 Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Tue, 22 Aug 2017 18:03:32 -0400 Subject: [PATCH 1/3] Fix compilation in ftp.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When trying to compile the file ftp.c, I get errors related with warnings that were marked to be reported as error. This was the original message: ``` fetch/ftp.c:444:8: error: this statement may fall through [-Werror=implicit-fallthrough=] type = 'D'; ~~~~~^~~~~ fetch/ftp.c:445:2: note: here case 'D': ^~~~ fetch/ftp.c: In function ‘ftp_request’: fetch/ftp.c:342:3: error: missed loop optimization, the loop counter may overflow [-Werror=unsafe-loop-optimizations] for (i = 0; i <= len && i <= end - dst; ++i) ^~~ fetch/ftp.c:342:24: error: missed loop optimization, the loop counter may overflow [-Werror=unsafe-loop-optimizations] for (i = 0; i <= len && i <= end - dst; ++i) ~~~~~~~~~^~~~~~~~~~~~~~~~~ ``` --- lib/fetch/ftp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/fetch/ftp.c b/lib/fetch/ftp.c index e7ba9039..28296a00 100644 --- a/lib/fetch/ftp.c +++ b/lib/fetch/ftp.c @@ -339,7 +339,7 @@ ftp_cwd(conn_t *conn, const char *path, int subdir) len = strlen(pwd); /* Look for a common prefix between PWD and dir to fetch. */ - for (i = 0; i <= len && i <= end - dst; ++i) + for (i = 0; i < len && i < end - dst; ++i) if (pwd[i] != dst[i]) break; /* Keep going up a dir until we have a matching prefix. */ @@ -440,10 +440,6 @@ ftp_mode_type(conn_t *conn, int mode, int type) type = 'A'; case 'A': break; - case 'd': - type = 'D'; - case 'D': - /* can't handle yet */ default: return (FTP_PROTOCOL_ERROR); } From 2cd0dc688ff9acc8f9b20588ebb373db1abdb9b3 Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Tue, 22 Aug 2017 18:35:45 -0400 Subject: [PATCH 2/3] Fix compilation of initend for gcc 7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a trickier situation. The original message: ``` initend.c:423:10: error: ‘%s’ directive output may be truncated writing 15 bytes into a region of size between 1 and 512 [-Werror=format-truncation=] "%s%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ^~ initend.c:422:3: note: ‘snprintf’ output between 16 and 527 bytes into a destination of size 512 snprintf(xhp->confdir, sizeof(xhp->confdir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XBPS_SYSCONF_PATH); ~~~~~~~~~~~~~~~~~~ initend.c:429:7: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation ] "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); ^~~~~~~ initend.c:428:3: note: ‘snprintf’ output 2 or more bytes (assuming 513) into a destination of size 512 snprintf(xhp->confdir, sizeof(xhp->confdir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ initend.c:434:9: error: ‘%s’ directive output may be truncated writing 17 bytes into a region of size between 1 and 512 [-Werror=format-truncation=] "%s%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ^~ initend.c:433:2: note: ‘snprintf’ output between 18 and 529 bytes into a destination of size 512 snprintf(sysconfdir, sizeof(sysconfdir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XBPS_SYSDEFCONF_PATH); ~~~~~~~~~~~~~~~~~~~~~ initend.c:455:11: error: ‘%s’ directive output may be truncated writing 14 bytes into a region of size between 0 and 511 [-Werror=format-truncation=] "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ^~ initend.c:454:3: note: ‘snprintf’ output between 16 and 527 bytes into a destination of size 512 snprintf(xhp->cachedir, sizeof(xhp->cachedir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XBPS_CACHE_PATH); ~~~~~~~~~~~~~~~~ initend.c:461:7: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation ] "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); ^~~~~~~ initend.c:460:3: note: ‘snprintf’ output 2 or more bytes (assuming 513) into a destination of size 512 snprintf(xhp->cachedir, sizeof(xhp->cachedir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ initend.c:467:11: error: ‘%s’ directive output may be truncated writing 12 bytes into a region of size between 0 and 511 [-Werror=format-truncation=] "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ^~ initend.c:466:3: note: ‘snprintf’ output between 14 and 525 bytes into a destination of size 512 snprintf(xhp->metadir, sizeof(xhp->metadir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XBPS_META_PATH); ~~~~~~~~~~~~~~~ initend.c:473:7: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation ] "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); ^~~~~~~ initend.c:472:3: note: ‘snprintf’ output 2 or more bytes (assuming 513) into a destination of size 512 snprintf(xhp->metadir, sizeof(xhp->metadir), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` It's basically warning about dangerous operations on strings. And as far as I could tell, is a valid warning and not a false alarm! This fix makes the concept of `XBPS_MAXPATH` lose a little bit of sense as now it doesn't necessarily represent the max size of the paths used by xbps, but instead the max allowed size of the path configured. I think this change is ok, but I wasn't able to find any reference to why it was chosen to be 512. POSIX mandates at least 256, so I'm not breaking anything that wasn't broken already, and Linux seems to have a maximum size of 4096, which is pretty safe. Therefore, this changes should be harmless. I think. --- include/xbps.h.in | 6 +++--- lib/initend.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/xbps.h.in b/include/xbps.h.in index 6c1a7964..5b37c196 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -592,7 +592,7 @@ struct xbps_handle { * * Full path to the xbps configuration directory. */ - char confdir[XBPS_MAXPATH]; + char confdir[XBPS_MAXPATH+sizeof(XBPS_SYSCONF_PATH)]; /** * @var rootdir * @@ -606,14 +606,14 @@ struct xbps_handle { * Cache directory to store downloaded binary packages. * If unset, defaults to \a XBPS_CACHE_PATH (relative to rootdir). */ - char cachedir[XBPS_MAXPATH]; + char cachedir[XBPS_MAXPATH+sizeof(XBPS_CACHE_PATH)]; /** * @var metadir * * Metadata directory for all operations in XBPS. * If unset, defaults to \a XBPS_CACHE_PATH (relative to rootdir). */ - char metadir[XBPS_MAXPATH]; + char metadir[XBPS_MAXPATH+sizeof(XBPS_META_PATH)]; /** * @var native_arch * diff --git a/lib/initend.c b/lib/initend.c index 3a31fcfc..7b796148 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -397,7 +397,7 @@ int xbps_init(struct xbps_handle *xhp) { struct utsname un; - char cwd[PATH_MAX-1], sysconfdir[XBPS_MAXPATH], *buf; + char cwd[PATH_MAX-1], sysconfdir[XBPS_MAXPATH+sizeof(XBPS_SYSDEFCONF_PATH)], *buf; const char *repodir, *native_arch; int rv; From 51207b9076f43351ad88c68be4febd03993a683c Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Tue, 22 Aug 2017 18:44:32 -0400 Subject: [PATCH 3/3] fix compilation of fetch_cb on gcc 7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original message: ``` fetch_cb.c:80:29: error: ‘h’ directive output may be truncated writing 1 byte into a region of size between 0 and 14 [-Werror=format-truncation=] snprintf(str, sizeof str, "%02ldh%02ldm", ^~~~~~~~~~~~~~ fetch_cb.c:80:29: note: directive argument in the range [0, 59] fetch_cb.c:80:3: note: ‘snprintf’ output between 7 and 21 bytes into a destination of size 16 snprintf(str, sizeof str, "%02ldh%02ldm", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eta / 3600, (eta % 3600) / 60); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fetch_cb.c:83:30: error: ‘%02ld’ directive output may be truncated writing between 2 and 19 bytes into a region of size 16 [-Werror=format-truncation=] snprintf(str, sizeof str, "%02ldm%02lds", ^~~~~ fetch_cb.c:83:29: note: directive argument in the range [-153722867280912930, 60] snprintf(str, sizeof str, "%02ldm%02lds", ^~~~~~~~~~~~~~ fetch_cb.c:83:29: note: directive argument in the range [-59, 59] fetch_cb.c:83:3: note: ‘snprintf’ output between 7 and 25 bytes into a destination of size 16 snprintf(str, sizeof str, "%02ldm%02lds", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eta / 60, eta % 60); ~~~~~~~~~~~~~~~~~~~ fetch_cb.c:80:29: error: ‘h’ directive output may be truncated writing 1 byte into a region of size between 0 and 14 [-Werror=format-truncation=] snprintf(str, sizeof str, "%02ldh%02ldm", ^~~~~~~~~~~~~~ fetch_cb.c:80:29: note: directive argument in the range [0, 59] fetch_cb.c:80:3: note: ‘snprintf’ output between 7 and 21 bytes into a destination of size 16 snprintf(str, sizeof str, "%02ldh%02ldm", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eta / 3600, (eta % 3600) / 60); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fetch_cb.c:83:30: error: ‘%02ld’ directive output may be truncated writing between 2 and 19 bytes into a region of size 16 [-Werror=format-truncation=] snprintf(str, sizeof str, "%02ldm%02lds", ^~~~~ fetch_cb.c:83:29: note: directive argument in the range [-153722867280912930, 60] snprintf(str, sizeof str, "%02ldm%02lds", ^~~~~~~~~~~~~~ fetch_cb.c:83:29: note: directive argument in the range [-59, 59] fetch_cb.c:83:3: note: ‘snprintf’ output between 7 and 25 bytes into a destination of size 16 snprintf(str, sizeof str, "%02ldm%02lds", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eta / 60, eta % 60); ~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` --- bin/xbps-install/fetch_cb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/xbps-install/fetch_cb.c b/bin/xbps-install/fetch_cb.c index a0f158d3..8d10ac17 100644 --- a/bin/xbps-install/fetch_cb.c +++ b/bin/xbps-install/fetch_cb.c @@ -65,7 +65,7 @@ static const char * stat_eta(const struct xbps_fetch_cb_data *xfpd, void *cbdata) { struct xferstat *xfer = cbdata; - static char str[16]; + static char str[25]; long elapsed, eta; off_t received, expected;