From: Michael R Sweet Date: Wed, 2 Apr 2025 19:38:47 +0000 (-0400) Subject: Use cupsdCreateConfFile and friends when updating a PPD file (Issue #1109) X-Git-Tag: v2.4.12~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2d3da4a12b55003dd5c3b4a432bca0bf22e304b;p=thirdparty%2Fcups.git Use cupsdCreateConfFile and friends when updating a PPD file (Issue #1109) --- diff --git a/CHANGES.md b/CHANGES.md index f271a91b9b..ffea3754c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ Changes in CUPS v2.4.12 (YYYY-MM-DD) - GnuTLS follows system crypto policies now (Issue #1105) - Added `NoSystem` SSLOptions value (Issue #1130) +- Fixed a potential "lost PPD" condition in the scheduler (Issue #1109) - Fixed a compressed file error handling bug (Issue #1070) - Fixed a bug in the make-and-model whitespace trimming code (Issue #1096) - Fixed a removal of IPP Everywhere permanent queue if installation failed (Issue #1102) diff --git a/scheduler/printers.c b/scheduler/printers.c index 34e95efbbb..8b25cf30dc 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -1,7 +1,7 @@ /* * Printer routines for the CUPS scheduler. * - * Copyright © 2020-2024 by OpenPrinting + * Copyright © 2020-2025 by OpenPrinting * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2007 by Easy Software Products, all rights reserved. * @@ -2794,8 +2794,7 @@ cupsdUpdatePrinterPPD( int i; /* Looping var */ cups_file_t *src, /* Original file */ *dst; /* New file */ - char srcfile[1024], /* Original filename */ - dstfile[1024], /* New filename */ + char filename[1024], /* PPD filename */ line[1024], /* Line from file */ keystring[41]; /* Keyword from line */ cups_option_t *keyword; /* Current keyword */ @@ -2805,37 +2804,21 @@ cupsdUpdatePrinterPPD( p->name); /* - * Get the old and new PPD filenames... + * Get the base PPD filename... */ - snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name); - snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name); + snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, p->name); /* - * Rename the old file and open the old and new... + * Open the old and new PPDs... */ - if (rename(dstfile, srcfile)) - { - cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup PPD file for %s: %s", - p->name, strerror(errno)); + if ((src = cupsdOpenConfFile(filename)) == NULL) return (0); - } - if ((src = cupsFileOpen(srcfile, "r")) == NULL) + if ((dst = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL) { - cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s", - srcfile, strerror(errno)); - rename(srcfile, dstfile); - return (0); - } - - if ((dst = cupsFileOpen(dstfile, "w")) == NULL) - { - cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s", - dstfile, strerror(errno)); cupsFileClose(src); - rename(srcfile, dstfile); return (0); } @@ -2845,11 +2828,9 @@ cupsdUpdatePrinterPPD( if (!cupsFileGets(src, line, sizeof(line))) { - cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", - srcfile, strerror(errno)); + cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", filename, strerror(errno)); cupsFileClose(src); cupsFileClose(dst); - rename(srcfile, dstfile); return (0); } @@ -2887,7 +2868,7 @@ cupsdUpdatePrinterPPD( */ cupsFileClose(src); - cupsFileClose(dst); + cupsdCloseCreatedConfFile(dst, filename); return (1); } @@ -3448,7 +3429,7 @@ add_printer_filter( } do - { + { ptr ++; } while (_cups_isspace(*ptr));