Skip to content

Commit

Permalink
rpm2cpio and rpm2archive: don't write archive data to a terminal.
Browse files Browse the repository at this point in the history
rpm2cpio and rpm2archive happily write binary data to the output
terminal.  This happens, for example, when I'm typing a command such as
"rpm2cpio foo.rpm | less" and I make a typo, hitting <Return> instead of
the pipe key.  This often results in hilarious (if bewildering) font and
character encoding changes.  On some systems, this can even result in
installation of relatively arbitrary rpms!

Nobody has ever meant to do this, and it's easy to prevent, so that's
what this patch does.
  • Loading branch information
vathpela authored and ffesti committed Jan 26, 2017
1 parent 2f587f8 commit 034f1cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rpm2archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <archive.h>
#include <archive_entry.h>
#include <unistd.h>

#include "debug.h"

Expand Down Expand Up @@ -120,7 +121,11 @@ static int process_package(rpmts ts, char * filename)
archive_write_set_format_pax_restricted(a);

if (!strcmp(filename, "-")) {
archive_write_open_fd(a, 1);
if (isatty(STDOUT_FILENO)) {
fprintf(stderr, "Error: refusing to output archive data to a terminal.\n");
exit(EXIT_FAILURE);
}
archive_write_open_fd(a, STDOUT_FILENO);
} else {
char * outname = rstrscat(NULL, filename, ".tgz", NULL);
archive_write_open_filename(a, outname);
Expand Down
5 changes: 5 additions & 0 deletions rpm2cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rpm/rpmpgp.h>

#include <rpm/rpmts.h>
#include <unistd.h>

#include "debug.h"

Expand Down Expand Up @@ -38,6 +39,10 @@ int main(int argc, char *argv[])
(argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
exit(EXIT_FAILURE);
}
if (isatty(STDOUT_FILENO)) {
fprintf(stderr, "Error: refusing to output cpio data to a terminal.\n");
exit(EXIT_FAILURE);
}
fdo = fdDup(STDOUT_FILENO);

{ rpmts ts = rpmtsCreate();
Expand Down

0 comments on commit 034f1cc

Please sign in to comment.