From 484bd75ce48ade2c34f730c16e783da284a0a509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Wed, 17 Mar 2021 14:40:04 +0000 Subject: [PATCH] tftp warning fix. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At least on Fedora 32 with GCC 10.2.1, dnsmasq compilation emits warning: tftp.c: In function ‘tftp_request’: tftp.c:754:3: warning: ‘strcpy’ source argument is the same as destination [-Wrestrict] 754 | strcpy(daemon->namebuff, file); And indeed it is the same source always on line 477, sometimes also on 571 in tftp.c Attached patch fixes the warning and possible undefined behaviour on tftp error. --- src/tftp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tftp.c b/src/tftp.c index 846b32e..ce7b56d 100644 --- a/src/tftp.c +++ b/src/tftp.c @@ -22,7 +22,7 @@ static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len) static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix); static void free_transfer(struct tftp_transfer *transfer); static ssize_t tftp_err(int err, char *packet, char *message, char *file); -static ssize_t tftp_err_oops(char *packet, char *file); +static ssize_t tftp_err_oops(char *packet, const char *file); static ssize_t get_block(char *packet, struct tftp_transfer *transfer); static char *next(char **p, char *end); static void sanitise(char *buf); @@ -748,10 +748,11 @@ static ssize_t tftp_err(int err, char *packet, char *message, char *file) return ret; } -static ssize_t tftp_err_oops(char *packet, char *file) +static ssize_t tftp_err_oops(char *packet, const char *file) { /* May have >1 refs to file, so potentially mangle a copy of the name */ - strcpy(daemon->namebuff, file); + if (file != daemon->namebuff) + strcpy(daemon->namebuff, file); return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), daemon->namebuff); }