Skip to content

Commit

Permalink
tftp warning fix.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pemensik authored and simonkelley committed Mar 17, 2021
1 parent 4c30e96 commit 484bd75
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/tftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 484bd75

Please sign in to comment.