summaryrefslogtreecommitdiff
path: root/src/pacman
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-12-12 20:01:14 -0600
committerDan McGee <dan@archlinux.org>2010-12-12 20:01:14 -0600
commit0e39cf9275c6a6f965e364792527c2704327bd02 (patch)
tree396f8091e419507e33426e8330cb3c98dc5a676c /src/pacman
parenta35610beba1b12c37ec26ec878d3701dd669db42 (diff)
Ensure stdin args are correctly terminated
And don't require pm_targets to be empty to read from stdin either. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman')
-rw-r--r--src/pacman/pacman.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index e078aaba..39390a53 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1306,15 +1306,15 @@ int main(int argc, char *argv[])
cleanup(ret);
}
- /* read package arguments from stdin if we have none yet */
- if(!pm_targets && !isatty(fileno(stdin))) {
+ /* we also support reading targets from stdin */
+ if(!isatty(fileno(stdin))) {
char line[PATH_MAX];
int i = 0;
while(i < PATH_MAX && (line[i] = fgetc(stdin)) != EOF) {
if(isspace((unsigned char)line[i])) {
- line[i] = '\0';
/* avoid adding zero length arg when multiple spaces separate args */
if(i > 0) {
+ line[i] = '\0';
pm_targets = alpm_list_add(pm_targets, strdup(line));
i = 0;
}
@@ -1330,6 +1330,7 @@ int main(int argc, char *argv[])
/* end of stream -- check for data still in line buffer */
if(i > 0) {
+ line[i] = '\0';
pm_targets = alpm_list_add(pm_targets, strdup(line));
}
if (!freopen(ctermid(NULL), "r", stdin)) {