Skip to content

Commit

Permalink
Strip following whitespace in config file lines
Browse files Browse the repository at this point in the history
  • Loading branch information
gperciva committed Jul 31, 2015
1 parent 09cd28d commit 221949b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tar/bsdtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,18 +1166,22 @@ configfile_helper(struct bsdtar *bsdtar, const char *line)
if ((conf_opt = strdup(line)) == NULL)
bsdtar_errc(bsdtar, 1, errno, "Out of memory");

/*
* Detect any trailing whitespace. This could happen before string
* duplication, but to reduce the number of diffs to a later version,
* we'll do it here.
/* Skip any following whitespace.
* We cannot modify 'line' beacuse it is const, so we
* perform this step on the duplicated string.
*/
len = strlen(conf_opt);
if ((len > 0) &&
((conf_opt[len - 1] == ' ') || (conf_opt[len - 1] == '\t'))) {
bsdtar_warnc(bsdtar, 0,
"option contains trailing whitespace; future behaviour"
" may change for:\n %s", line);
"Automatically stripping trailing whitespace"
" in config file");
}
while ((len > 0) &&
((conf_opt[len - 1] == ' ') || (conf_opt[len - 1] == '\t'))) {
len--;
}
conf_opt[len] = '\0';

/* Split line into option and argument if possible. */
optlen = strcspn(conf_opt, " \t");
Expand Down

0 comments on commit 221949b

Please sign in to comment.