From: Mark Wielaard Date: Fri, 7 Feb 2020 23:17:25 +0000 (-0500) Subject: debuginfod: archive processing: handle -Z EXT=cat with direct fopen X-Git-Tag: elfutils-0.179~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=499129e77aa88b94756bd6c8d50347721689065c;p=thirdparty%2Felfutils.git debuginfod: archive processing: handle -Z EXT=cat with direct fopen Signed-off-by: Mark Wielaard --- diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 6d7290237..0acd70e4a 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -1160,11 +1160,24 @@ handle_buildid_r_match (int64_t b_mtime, archive_extension = arch.first; archive_decoder = arch.second; } - string popen_cmd = archive_decoder + " " + shell_escape(b_source0); - FILE* fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? - if (fp == NULL) - throw libc_exception (errno, string("popen ") + popen_cmd); - defer_dtor fp_closer (fp, pclose); + FILE* fp; + defer_dtor::dtor_fn dfn; + if (archive_decoder != "cat") + { + string popen_cmd = archive_decoder + " " + shell_escape(b_source0); + fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? + dfn = pclose; + if (fp == NULL) + throw libc_exception (errno, string("popen ") + popen_cmd); + } + else + { + fp = fopen (b_source0.c_str(), "r"); + dfn = fclose; + if (fp == NULL) + throw libc_exception (errno, string("fopen ") + b_source0); + } + defer_dtor fp_closer (fp, dfn); struct archive *a; a = archive_read_new(); @@ -2048,11 +2061,25 @@ archive_classify (const string& rps, string& archive_extension, archive_extension = arch.first; archive_decoder = arch.second; } - string popen_cmd = archive_decoder + " " + shell_escape(rps); - FILE* fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? - if (fp == NULL) - throw libc_exception (errno, string("popen ") + popen_cmd); - defer_dtor fp_closer (fp, pclose); + + FILE* fp; + defer_dtor::dtor_fn dfn; + if (archive_decoder != "cat") + { + string popen_cmd = archive_decoder + " " + shell_escape(rps); + fp = popen (popen_cmd.c_str(), "r"); // "e" O_CLOEXEC? + dfn = pclose; + if (fp == NULL) + throw libc_exception (errno, string("popen ") + popen_cmd); + } + else + { + fp = fopen (rps.c_str(), "r"); + dfn = fclose; + if (fp == NULL) + throw libc_exception (errno, string("fopen ") + rps); + } + defer_dtor fp_closer (fp, dfn); struct archive *a; a = archive_read_new();