Initial import (fedora#2170050)

This commit is contained in:
Zdenek Dohnal 2023-02-16 10:37:05 +01:00
parent e0a052eb8a
commit 7b16f04327
4 changed files with 347 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/libppd-2.0b3.tar.gz

154
0001-Coverity-fixes.patch Normal file
View File

@ -0,0 +1,154 @@
From 0d469d4fd01432462a7cf03bbb30568edb822695 Mon Sep 17 00:00:00 2001
From: Zdenek Dohnal <zdohnal@redhat.com>
Date: Tue, 14 Feb 2023 17:12:40 +0100
Subject: [PATCH] Coverity fixes
---
ppd/imagetops-pstops.c | 9 +++++++--
ppd/pdftops.c | 2 ++
ppd/ppd-collection.cxx | 5 ++++-
ppd/ppd-filter.c | 18 +++++++++++++-----
ppd/raster-interpret.c | 3 ++-
5 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/ppd/imagetops-pstops.c b/ppd/imagetops-pstops.c
index 7c5023d3..948ca0df 100644
--- a/ppd/imagetops-pstops.c
+++ b/ppd/imagetops-pstops.c
@@ -280,7 +280,6 @@ ppdFilterPSToPS(int inputfd, // I - File descriptor input stream
log, ld, iscanceled, icd) == 1)
{
close(inputfd);
- close(outputfd);
return (1);
}
@@ -401,6 +400,10 @@ ppdFilterPSToPS(int inputfd, // I - File descriptor input stream
"ppdFilterPSToPS: The print file is empty.");
// Do not treat this an error, if a previous filter eliminated all
// pages the job should get dequeued without anything printed.
+
+ fclose(outputfp);
+ cupsFileClose(inputfp);
+
return (0);
}
@@ -564,7 +567,6 @@ ppdFilterPSToPS(int inputfd, // I - File descriptor input stream
close(inputfd);
fclose(outputfp);
- close(outputfd);
return (status);
}
@@ -704,6 +706,9 @@ ppdFilterImageToPS(int inputfd, // I - File descriptor input
if (log) log(ld, CF_LOGLEVEL_ERROR,
"ppdFilterImageToPS: Unable to copy input: %s",
strerror(errno));
+
+ fclose(inputfp);
+
return (1);
}
diff --git a/ppd/pdftops.c b/ppd/pdftops.c
index a00b2260..c88d9ad9 100644
--- a/ppd/pdftops.c
+++ b/ppd/pdftops.c
@@ -373,6 +373,8 @@ ppdFilterPDFToPS(int inputfd, // I - File descriptor input stream
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"ppdFilterPDFToPS: Unable to copy PDF file: %s", strerror(errno));
+
+ fclose(inputfp);
return (1);
}
diff --git a/ppd/ppd-collection.cxx b/ppd/ppd-collection.cxx
index 68ea4db1..27a0b011 100644
--- a/ppd/ppd-collection.cxx
+++ b/ppd/ppd-collection.cxx
@@ -1573,8 +1573,11 @@ load_drv(const char *filename, // I - Actual filename
mtime, (size_t)size, d->model_number, type, "drv",
ppdlist, log, ld);
else if (products_found < PPD_MAX_PROD)
+ {
strncpy(ppd->record.products[products_found], product->value->value,
- sizeof(ppd->record.products[0]));
+ sizeof(ppd->record.products[0]) - 1);
+ ppd->record.products[products_found][sizeof(ppd->record.products[0]) - 1] = '\0';
+ }
else
break;
diff --git a/ppd/ppd-filter.c b/ppd/ppd-filter.c
index 4e2d2931..308336ad 100644
--- a/ppd/ppd-filter.c
+++ b/ppd/ppd-filter.c
@@ -46,6 +46,7 @@ ppdFilterCUPSWrapper(
cups_option_t *options = NULL; // Print options
cf_filter_data_t filter_data;
const char *val;
+ char *ppdfile = NULL;
char buf[256];
int retval = 0;
@@ -161,20 +162,26 @@ ppdFilterCUPSWrapper(
// to the filter_data structure
//
- if (getenv("PPD"))
- retval = ppdFilterLoadPPDFile(&filter_data, getenv("PPD"));
+ ppdfile = getenv("PPD");
+
+ if (ppdfile && (retval = ppdFilterLoadPPDFile(&filter_data, getenv("PPD"))) != 0)
+ {
+ fprintf(stderr, "ERROR: ppdFilterCUPSWrapper: Cannot open the PPD file %s\n", ppdfile);
+ close(inputfd);
+ goto out;
+ }
//
// Fire up the filter function (output to stdout, file descriptor 1)
//
- if (!retval)
- retval = filter(inputfd, 1, inputseekable, &filter_data, parameters);
+ retval = filter(inputfd, 1, inputseekable, &filter_data, parameters);
//
// Clean up
//
+out:
cupsFreeOptions(filter_data.num_options, filter_data.options);
ppdFilterFreePPDFile(&filter_data);
@@ -1570,7 +1577,8 @@ ppdFilterUniversal(int inputfd, // I - File descriptor input stream
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"ppdFilterUniversal: --> Selecting this line");
// Take the input format of the line as output format for us
- strncpy(output, in, sizeof(output));
+ strncpy(output, in, sizeof(output) - 1);
+ output[sizeof(output) - 1] = '\0';
// Update the minimum cost found
lowest_cost = cost;
// We cannot find a "better" solution ...
diff --git a/ppd/raster-interpret.c b/ppd/raster-interpret.c
index efa99d7e..cff216e7 100644
--- a/ppd/raster-interpret.c
+++ b/ppd/raster-interpret.c
@@ -526,7 +526,8 @@ ppdRasterMatchPPDSize(
return (-1);
}
- strncpy(pageSizeRequested, header->cupsPageSizeName, 64);
+ strncpy(pageSizeRequested, header->cupsPageSizeName, 63);
+ pageSizeRequested[63] = "\0";
// Prefer user-selected page size.
memset(dimensions, 0, sizeof(double)*2);
memset(margins, 0, sizeof(double)*4);
--
2.39.1

191
libppd.spec Normal file
View File

@ -0,0 +1,191 @@
%global _hardened_build 1
# don't build libppd-tools until CUPS 3.x drops them
%bcond_with tools
Name: libppd
Version: 2.0b3
Release: 1%{?dist}
Summary: Library for retro-fitting legacy printer drivers
# the CUPS exception text is the same as LLVM exception, so using that name with
# agreement from legal team
# https://lists.fedoraproject.org/archives/list/legal@lists.fedoraproject.org/message/A7GFSD6M3GYGSI32L2FC5KB22DUAEQI3/
License: Apache-2.0 WITH LLVM-exception
URL: https://github.com/OpenPrinting/libppd
Source0: %{URL}/archive/%{version}/%{name}-%{version}.tar.gz
# Patches
# https://github.com/OpenPrinting/libppd/pull/9
Patch0001: 0001-Coverity-fixes.patch
# for autogen.sh
BuildRequires: autoconf
# for autogen.sh
BuildRequires: automake
# mostly written in C
BuildRequires: gcc
# PPD compiler support written in C++
BuildRequires: gcc-c++
# for autogen.sh
BuildRequires: gettext-devel
# ghostscript is needed during build due configure check
BuildRequires: ghostscript >= 10.0.0
# for autosetup
BuildRequires: git-core
# for autogen.sh
BuildRequires: libtool
# uses make
BuildRequires: make
# for pkg-config in SPEC file and in configure
BuildRequires: pkgconf-pkg-config
# for CUPS API functions
BuildRequires: pkgconfig(cups) >= 2.2.2
# for filter functions
BuildRequires: pkgconfig(libcupsfilters) >= 2.0b3
# for rastertops
BuildRequires: pkgconfig(zlib)
# pdftops has to be in buildroot due configure check
BuildRequires: poppler-utils
%if %{without tools}
# libppd exports symbols for compiling PPD compilers, which needs charset
# definitions and header files during runtime to generate a PPD file - those
# are provided by cups right now - once cups drops them, require libppd-tools
Requires: cups
%else
Requires: %{name}-tools%{?_isa} = %{version}-%{release}
%endif
# needded for hybrid pdftops filter function - for all legacy printers
# except for Brother and Minolta/Konica Minolta, which firmware bugs
# doesn't work with pdftops from GS
Requires: ghostscript >= 10.0.0
# needed for hybrid pdftops filter function - for Brother and Minolta/
# Konica Minolta printers
Requires: poppler-utils
%description
Libppd provides all PPD related function/API which is going
to be removed from CUPS 3.X, but are still required for retro-fitting
support of legacy printers. The library is meant only for retro-fitting
printer applications, any new printer drivers have to be written as
native printer application without libppd.
%package devel
Summary: Development files for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: cups-devel
Requires: libcupsfilters-devel
%description devel
The %{name}-devel package contains libraries and header files for
developing retro-fitting printer applications.
%if %{with tools}
%package tools
Summary: PPD compiler tools and definition files
Requires: %{name}%{?_isa} = %{version}-%{release}
%description tools
The package contains PPD compiler and definition files needed for generating
PPD files from *.drv files.
%endif
%prep
%autosetup -S git
%build
# generate configuration/compilation files
./autogen.sh
# disable PPD compiler tools for now (until CUPS 3.x drops PPD support) to prevent
# conflicts with cups 2.x package
%configure\
--disable-acroread\
--disable-mutool\
--disable-rpath\
--disable-silent-rules\
--disable-static\
%if %{with tools}
--enable-ppdc-utils\
%else
--disable-ppdc-utils\
%endif
--with-pdftops=hybrid
# fix rpmlint error about linking to libraries, but not actually using their functions
# it happens when the required libraries uses pkgconfig - pkgconfig file doesn't know
# which specific functions our binary calls, so it tells us to link against every
# possibilities
# https://fedoraproject.org/wiki/Common_Rpmlint_issues#unused-direct-shlib-dependency
sed -i -e 's! -shared ! -Wl,--as-needed\0!g' libtool
%make_build
%check
make check
%install
%make_install
find %{buildroot} -name '*.la' -exec rm -f {} ';'
# remove the license files from doc dir, since we ship them in /usr/share/licenses
rm -f %{buildroot}%{_pkgdocdir}/{LICENSE,NOTICE,COPYING}
# remove INSTALL since it is unnecessary
rm -f %{buildroot}%{_pkgdocdir}/INSTALL
# 1.x was the release were all cups-filters components were together
# let only libcupsfilters to carry it
rm -f %{buildroot}%{_pkgdocdir}/CHANGES-1.x.md
# charsets and header files needed for PPD compilation in runtime
# are for now shipped by cups - libppd will ship them once cups
# drops them
%if %{without tools}
rm -rf %{buildroot}%{_datadir}/ppdc
%endif
%{?ldconfig_scriptlets}
%files
%license LICENSE NOTICE COPYING
%doc ABOUT-NLS AUTHORS CHANGES.md README.md
%{_libdir}/libppd.so.2*
%files devel
%{_docdir}/%{name}/CONTRIBUTING.md
%{_docdir}/%{name}/DEVELOPING.md
%dir %{_includedir}/ppd
%{_includedir}/ppd/ppd-filter.h
%{_includedir}/ppd/ppdc.h
%{_includedir}/ppd/ppd.h
%{_libdir}/libppd.so
%{_libdir}/pkgconfig/libppd.pc
%if %{with tools}
%files tools
%{_bindir}/ppdc
%{_bindir}/ppdhtml
%{_bindir}/ppdi
%{_bindir}/ppdmerge
%{_bindir}/ppdpo
%dir %{_datadir}/ppdc/
%{_datadir}/ppdc/epson.h
%{_datadir}/ppdc/font.defs
%{_datadir}/ppdc/hp.h
%{_datadir}/ppdc/label.h
%{_datadir}/ppdc/media.defs
%{_datadir}/ppdc/raster.defs
%endif
%changelog
* Wed Feb 01 2023 Zdenek Dohnal <zdohnal@redhat.com> - 2.0b3-1
- Initial import

1
sources Normal file
View File

@ -0,0 +1 @@
SHA512 (libppd-2.0b3.tar.gz) = 2ce9592bd28f3957f849c504cd85380b5f125cd057f0299899cf87ec86d74acd33fd13271d52cd33e5a7028bfd8ec75f1a0996db87f79764532f601e371dcd03