From 5a00cf374d4f26b24ea71b14cc50c9b1c404f906 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 21 Jan 2019 14:12:43 -0500 Subject: [PATCH] Fix potential unaligned accesses in the string pool (Issue #5474) This set of changes makes the PPD functions use strdup and free - they were modifying the contents of the string in places and doing other things that were not safe for (immutable) strings in the pool. --- CHANGES.md | 1 + cups/ppd-cache.c | 136 +++++++++++++++++++++-------------------------- cups/ppd-mark.c | 12 ++--- cups/ppd.c | 115 +++++++++++++++++++-------------------- 4 files changed, 123 insertions(+), 141 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0d39f6a64..56f36c1af 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Changes in CUPS v2.3b8 - Fixed a potential crash bug in cups-driverd (rdar://46625579) - Fixed a performance regression with large PPDs (rdar://47040759) - Fixed a potential memory leak when reading at the end of a file (Issue #5473) +- Fixed potential unaligned accesses in the string pool (Issue #5474) - Fixed a potential memory leak when loading a PPD file (Issue #5475) - Added a USB quirks rule for the Lexmark E120n (Issue #5478) - Fixed a compile error on Linux (Issue #5483) diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index 9ec6ab07e..30287bb29 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -533,24 +533,20 @@ _ppdCacheCreateWithFile( else if (!_cups_strcasecmp(line, "Filter")) { if (!pc->filters) - pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); cupsArrayAdd(pc->filters, value); } else if (!_cups_strcasecmp(line, "PreFilter")) { if (!pc->prefilters) - pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); cupsArrayAdd(pc->prefilters, value); } else if (!_cups_strcasecmp(line, "Product")) { - pc->product = _cupsStrAlloc(value); + pc->product = strdup(value); } else if (!_cups_strcasecmp(line, "SingleFile")) { @@ -650,8 +646,8 @@ _ppdCacheCreateWithFile( } map = pc->bins + pc->num_bins; - map->pwg = _cupsStrAlloc(pwg_keyword); - map->ppd = _cupsStrAlloc(ppd_keyword); + map->pwg = strdup(pwg_keyword); + map->ppd = strdup(ppd_keyword); pc->num_bins ++; } @@ -705,8 +701,8 @@ _ppdCacheCreateWithFile( goto create_error; } - size->map.pwg = _cupsStrAlloc(pwg_keyword); - size->map.ppd = _cupsStrAlloc(ppd_keyword); + size->map.pwg = strdup(pwg_keyword); + size->map.ppd = strdup(ppd_keyword); pc->num_sizes ++; } @@ -734,15 +730,15 @@ _ppdCacheCreateWithFile( pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "max", pc->custom_max_width, pc->custom_max_length, NULL); - pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword); + pc->custom_max_keyword = strdup(pwg_keyword); pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "min", pc->custom_min_width, pc->custom_min_length, NULL); - pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword); + pc->custom_min_keyword = strdup(pwg_keyword); } else if (!_cups_strcasecmp(line, "SourceOption")) { - pc->source_option = _cupsStrAlloc(value); + pc->source_option = strdup(value); } else if (!_cups_strcasecmp(line, "NumSources")) { @@ -789,8 +785,8 @@ _ppdCacheCreateWithFile( } map = pc->sources + pc->num_sources; - map->pwg = _cupsStrAlloc(pwg_keyword); - map->ppd = _cupsStrAlloc(ppd_keyword); + map->pwg = strdup(pwg_keyword); + map->ppd = strdup(ppd_keyword); pc->num_sources ++; } @@ -838,8 +834,8 @@ _ppdCacheCreateWithFile( } map = pc->types + pc->num_types; - map->pwg = _cupsStrAlloc(pwg_keyword); - map->ppd = _cupsStrAlloc(ppd_keyword); + map->pwg = strdup(pwg_keyword); + map->ppd = strdup(ppd_keyword); pc->num_types ++; } @@ -869,13 +865,13 @@ _ppdCacheCreateWithFile( pc->presets[print_color_mode] + print_quality); } else if (!_cups_strcasecmp(line, "SidesOption")) - pc->sides_option = _cupsStrAlloc(value); + pc->sides_option = strdup(value); else if (!_cups_strcasecmp(line, "Sides1Sided")) - pc->sides_1sided = _cupsStrAlloc(value); + pc->sides_1sided = strdup(value); else if (!_cups_strcasecmp(line, "Sides2SidedLong")) - pc->sides_2sided_long = _cupsStrAlloc(value); + pc->sides_2sided_long = strdup(value); else if (!_cups_strcasecmp(line, "Sides2SidedShort")) - pc->sides_2sided_short = _cupsStrAlloc(value); + pc->sides_2sided_short = strdup(value); else if (!_cups_strcasecmp(line, "Finishings")) { if (!pc->finishings) @@ -896,20 +892,20 @@ _ppdCacheCreateWithFile( else if (!_cups_strcasecmp(line, "FinishingTemplate")) { if (!pc->templates) - pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree); + pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); cupsArrayAdd(pc->templates, value); } else if (!_cups_strcasecmp(line, "MaxCopies")) pc->max_copies = atoi(value); else if (!_cups_strcasecmp(line, "ChargeInfoURI")) - pc->charge_info_uri = _cupsStrAlloc(value); + pc->charge_info_uri = strdup(value); else if (!_cups_strcasecmp(line, "JobAccountId")) pc->account_id = !_cups_strcasecmp(value, "true"); else if (!_cups_strcasecmp(line, "JobAccountingUserId")) pc->accounting_user_id = !_cups_strcasecmp(value, "true"); else if (!_cups_strcasecmp(line, "JobPassword")) - pc->password = _cupsStrAlloc(value); + pc->password = strdup(value); else if (!_cups_strcasecmp(line, "Mandatory")) { if (pc->mandatory) @@ -920,9 +916,7 @@ _ppdCacheCreateWithFile( else if (!_cups_strcasecmp(line, "SupportFile")) { if (!pc->support_files) - pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); cupsArrayAdd(pc->support_files, value); } @@ -1166,8 +1160,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ */ new_size = old_size; - _cupsStrFree(old_size->map.ppd); - _cupsStrFree(old_size->map.pwg); + free(old_size->map.ppd); + free(old_size->map.pwg); } } @@ -1188,8 +1182,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ * Save this size... */ - new_size->map.ppd = _cupsStrAlloc(ppd_size->name); - new_size->map.pwg = _cupsStrAlloc(pwg_name); + new_size->map.ppd = strdup(ppd_size->name); + new_size->map.pwg = strdup(pwg_name); new_size->width = new_width; new_size->length = new_length; new_size->left = new_left; @@ -1209,14 +1203,14 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "max", PWG_FROM_POINTS(ppd->custom_max[0]), PWG_FROM_POINTS(ppd->custom_max[1]), NULL); - pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword); + pc->custom_max_keyword = strdup(pwg_keyword); pc->custom_max_width = PWG_FROM_POINTS(ppd->custom_max[0]); pc->custom_max_length = PWG_FROM_POINTS(ppd->custom_max[1]); pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "min", PWG_FROM_POINTS(ppd->custom_min[0]), PWG_FROM_POINTS(ppd->custom_min[1]), NULL); - pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword); + pc->custom_min_keyword = strdup(pwg_keyword); pc->custom_min_width = PWG_FROM_POINTS(ppd->custom_min[0]); pc->custom_min_length = PWG_FROM_POINTS(ppd->custom_min[1]); @@ -1235,7 +1229,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ if (input_slot) { - pc->source_option = _cupsStrAlloc(input_slot->keyword); + pc->source_option = strdup(input_slot->keyword); if ((pc->sources = calloc((size_t)input_slot->num_choices, sizeof(pwg_map_t))) == NULL) { @@ -1287,8 +1281,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ "_"); } - map->pwg = _cupsStrAlloc(pwg_name); - map->ppd = _cupsStrAlloc(choice->choice); + map->pwg = strdup(pwg_name); + map->ppd = strdup(choice->choice); /* * Add localized text for PWG keyword to message catalog... @@ -1358,8 +1352,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ "_"); } - map->pwg = _cupsStrAlloc(pwg_name); - map->ppd = _cupsStrAlloc(choice->choice); + map->pwg = strdup(pwg_name); + map->ppd = strdup(choice->choice); /* * Add localized text for PWG keyword to message catalog... @@ -1392,8 +1386,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ { pwg_unppdize_name(choice->choice, pwg_keyword, sizeof(pwg_keyword), "_"); - map->pwg = _cupsStrAlloc(pwg_keyword); - map->ppd = _cupsStrAlloc(choice->choice); + map->pwg = strdup(pwg_keyword); + map->ppd = strdup(choice->choice); /* * Add localized text for PWG keyword to message catalog... @@ -1626,7 +1620,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ if (duplex) { - pc->sides_option = _cupsStrAlloc(duplex->keyword); + pc->sides_option = strdup(duplex->keyword); for (i = duplex->num_choices, choice = duplex->choices; i > 0; @@ -1634,16 +1628,16 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ { if ((!_cups_strcasecmp(choice->choice, "None") || !_cups_strcasecmp(choice->choice, "False")) && !pc->sides_1sided) - pc->sides_1sided = _cupsStrAlloc(choice->choice); + pc->sides_1sided = strdup(choice->choice); else if ((!_cups_strcasecmp(choice->choice, "DuplexNoTumble") || !_cups_strcasecmp(choice->choice, "LongEdge") || !_cups_strcasecmp(choice->choice, "Top")) && !pc->sides_2sided_long) - pc->sides_2sided_long = _cupsStrAlloc(choice->choice); + pc->sides_2sided_long = strdup(choice->choice); else if ((!_cups_strcasecmp(choice->choice, "DuplexTumble") || !_cups_strcasecmp(choice->choice, "ShortEdge") || !_cups_strcasecmp(choice->choice, "Bottom")) && !pc->sides_2sided_short) - pc->sides_2sided_short = _cupsStrAlloc(choice->choice); + pc->sides_2sided_short = strdup(choice->choice); } } @@ -1651,9 +1645,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ * Copy filters and pre-filters... */ - pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); cupsArrayAdd(pc->filters, "application/vnd.cups-raw application/octet-stream 0 -"); @@ -1710,9 +1702,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ if ((ppd_attr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL) { - pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); do { @@ -1729,7 +1719,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ */ if (ppd->product) - pc->product = _cupsStrAlloc(ppd->product); + pc->product = strdup(ppd->product); /* * Copy finishings mapping data... @@ -1869,7 +1859,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ if ((ppd_option = ppdFindOption(ppd, "cupsFinishingTemplate")) != NULL) { - pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree); + pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); for (choice = ppd_option->choices, i = ppd_option->num_choices; i > 0; choice ++, i --) { @@ -1901,7 +1891,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ */ if ((ppd_attr = ppdFindAttr(ppd, "cupsChargeInfoURI", NULL)) != NULL) - pc->charge_info_uri = _cupsStrAlloc(ppd_attr->value); + pc->charge_info_uri = strdup(ppd_attr->value); if ((ppd_attr = ppdFindAttr(ppd, "cupsJobAccountId", NULL)) != NULL) pc->account_id = !_cups_strcasecmp(ppd_attr->value, "true"); @@ -1910,7 +1900,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ pc->accounting_user_id = !_cups_strcasecmp(ppd_attr->value, "true"); if ((ppd_attr = ppdFindAttr(ppd, "cupsJobPassword", NULL)) != NULL) - pc->password = _cupsStrAlloc(ppd_attr->value); + pc->password = strdup(ppd_attr->value); if ((ppd_attr = ppdFindAttr(ppd, "cupsMandatory", NULL)) != NULL) pc->mandatory = _cupsArrayNewStrings(ppd_attr->value, ' '); @@ -1919,9 +1909,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ * Support files... */ - pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); for (ppd_attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); ppd_attr; @@ -1977,8 +1965,8 @@ _ppdCacheDestroy(_ppd_cache_t *pc) /* I - PPD cache and mapping data */ { for (i = pc->num_bins, map = pc->bins; i > 0; i --, map ++) { - _cupsStrFree(map->pwg); - _cupsStrFree(map->ppd); + free(map->pwg); + free(map->ppd); } free(pc->bins); @@ -1988,22 +1976,21 @@ _ppdCacheDestroy(_ppd_cache_t *pc) /* I - PPD cache and mapping data */ { for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) { - _cupsStrFree(size->map.pwg); - _cupsStrFree(size->map.ppd); + free(size->map.pwg); + free(size->map.ppd); } free(pc->sizes); } - if (pc->source_option) - _cupsStrFree(pc->source_option); + free(pc->source_option); if (pc->sources) { for (i = pc->num_sources, map = pc->sources; i > 0; i --, map ++) { - _cupsStrFree(map->pwg); - _cupsStrFree(map->ppd); + free(map->pwg); + free(map->ppd); } free(pc->sources); @@ -2013,26 +2000,23 @@ _ppdCacheDestroy(_ppd_cache_t *pc) /* I - PPD cache and mapping data */ { for (i = pc->num_types, map = pc->types; i > 0; i --, map ++) { - _cupsStrFree(map->pwg); - _cupsStrFree(map->ppd); + free(map->pwg); + free(map->ppd); } free(pc->types); } - if (pc->custom_max_keyword) - _cupsStrFree(pc->custom_max_keyword); - - if (pc->custom_min_keyword) - _cupsStrFree(pc->custom_min_keyword); + free(pc->custom_max_keyword); + free(pc->custom_min_keyword); - _cupsStrFree(pc->product); + free(pc->product); cupsArrayDelete(pc->filters); cupsArrayDelete(pc->prefilters); cupsArrayDelete(pc->finishings); - _cupsStrFree(pc->charge_info_uri); - _cupsStrFree(pc->password); + free(pc->charge_info_uri); + free(pc->password); cupsArrayDelete(pc->mandatory); diff --git a/cups/ppd-mark.c b/cups/ppd-mark.c index eb476771e..9eca0cec7 100644 --- a/cups/ppd-mark.c +++ b/cups/ppd-mark.c @@ -1,8 +1,8 @@ /* * Option marking routines for CUPS. * - * Copyright 2007-2017 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright © 2007-2019 by Apple Inc. + * Copyright © 1997-2007 by Easy Software Products, all rights reserved. * * Licensed under Apache License v2.0. See the file "LICENSE" for more * information. @@ -886,9 +886,9 @@ ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */ case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : if (cparam->current.custom_string) - _cupsStrFree(cparam->current.custom_string); + free(cparam->current.custom_string); - cparam->current.custom_string = _cupsStrAlloc(choice + 7); + cparam->current.custom_string = strdup(choice + 7); break; } } @@ -963,9 +963,9 @@ ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */ case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : if (cparam->current.custom_string) - _cupsStrFree(cparam->current.custom_string); + free(cparam->current.custom_string); - cparam->current.custom_string = _cupsStrRetain(val->value); + cparam->current.custom_string = strdup(val->value); break; } } diff --git a/cups/ppd.c b/cups/ppd.c index 4560d9cfc..8bda7c6a0 100644 --- a/cups/ppd.c +++ b/cups/ppd.c @@ -23,8 +23,6 @@ * Definitions... */ -#define ppd_free(p) if (p) free(p) /* Safe free macro */ - #define PPD_KEYWORD 1 /* Line contained a keyword */ #define PPD_OPTION 2 /* Line contained an option name */ #define PPD_TEXT 4 /* Line contained human-readable text */ @@ -124,13 +122,12 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ * Free all strings at the top level... */ - _cupsStrFree(ppd->lang_encoding); - _cupsStrFree(ppd->nickname); - if (ppd->patches) - free(ppd->patches); - _cupsStrFree(ppd->jcl_begin); - _cupsStrFree(ppd->jcl_end); - _cupsStrFree(ppd->jcl_ps); + free(ppd->lang_encoding); + free(ppd->nickname); + free(ppd->patches); + free(ppd->jcl_begin); + free(ppd->jcl_end); + free(ppd->jcl_ps); /* * Free any UI groups, subgroups, and options... @@ -141,7 +138,7 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++) ppd_free_group(group); - ppd_free(ppd->groups); + free(ppd->groups); } cupsArrayDelete(ppd->options); @@ -152,14 +149,14 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ */ if (ppd->num_sizes > 0) - ppd_free(ppd->sizes); + free(ppd->sizes); /* * Free any constraints... */ if (ppd->num_consts > 0) - ppd_free(ppd->consts); + free(ppd->consts); /* * Free any filters... @@ -174,9 +171,9 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ if (ppd->num_fonts > 0) { for (i = ppd->num_fonts, font = ppd->fonts; i > 0; i --, font ++) - _cupsStrFree(*font); + free(*font); - ppd_free(ppd->fonts); + free(ppd->fonts); } /* @@ -184,7 +181,7 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ */ if (ppd->num_profiles > 0) - ppd_free(ppd->profiles); + free(ppd->profiles); /* * Free any attributes... @@ -194,11 +191,11 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ { for (i = ppd->num_attrs, attr = ppd->attrs; i > 0; i --, attr ++) { - _cupsStrFree((*attr)->value); - ppd_free(*attr); + free((*attr)->value); + free(*attr); } - ppd_free(ppd->attrs); + free(ppd->attrs); } cupsArrayDelete(ppd->sorted_attrs); @@ -220,7 +217,7 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ case PPD_CUSTOM_PASSCODE : case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : - _cupsStrFree(cparam->current.custom_string); + free(cparam->current.custom_string); break; default : @@ -268,7 +265,7 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ * Free the whole record... */ - ppd_free(ppd); + free(ppd); } @@ -606,15 +603,15 @@ _ppdOpen( if (pg->ppd_status == PPD_OK) pg->ppd_status = PPD_MISSING_PPDADOBE4; - _cupsStrFree(string); - ppd_free(line.buffer); + free(string); + free(line.buffer); return (NULL); } DEBUG_printf(("2_ppdOpen: keyword=%s, string=%p", keyword, string)); - _cupsStrFree(string); + free(string); /* * Allocate memory for the PPD file record... @@ -624,8 +621,8 @@ _ppdOpen( { pg->ppd_status = PPD_ALLOC_ERROR; - _cupsStrFree(string); - ppd_free(line.buffer); + free(string); + free(line.buffer); return (NULL); } @@ -822,7 +819,7 @@ _ppdOpen( * Say all PPD files are UTF-8, since we convert to UTF-8... */ - ppd->lang_encoding = _cupsStrAlloc("UTF-8"); + ppd->lang_encoding = strdup("UTF-8"); encoding = _ppdGetEncoding(string); } else if (!strcmp(keyword, "LanguageVersion")) @@ -843,10 +840,10 @@ _ppdOpen( cupsCharsetToUTF8(utf8, string, sizeof(utf8), encoding); - ppd->nickname = _cupsStrAlloc((char *)utf8); + ppd->nickname = strdup((char *)utf8); } else - ppd->nickname = _cupsStrAlloc(string); + ppd->nickname = strdup(string); } else if (!strcmp(keyword, "Product")) ppd->product = string; @@ -856,17 +853,17 @@ _ppdOpen( ppd->ttrasterizer = string; else if (!strcmp(keyword, "JCLBegin")) { - ppd->jcl_begin = _cupsStrAlloc(string); + ppd->jcl_begin = strdup(string); ppd_decode(ppd->jcl_begin); /* Decode quoted string */ } else if (!strcmp(keyword, "JCLEnd")) { - ppd->jcl_end = _cupsStrAlloc(string); + ppd->jcl_end = strdup(string); ppd_decode(ppd->jcl_end); /* Decode quoted string */ } else if (!strcmp(keyword, "JCLToPSInterpreter")) { - ppd->jcl_ps = _cupsStrAlloc(string); + ppd->jcl_ps = strdup(string); ppd_decode(ppd->jcl_ps); /* Decode quoted string */ } else if (!strcmp(keyword, "AccurateScreensSupport")) @@ -934,10 +931,10 @@ _ppdOpen( ppd->num_filters ++; /* - * Retain a copy of the filter string... + * Make a copy of the filter string... */ - *filter = _cupsStrRetain(string); + *filter = strdup(string); } else if (!strcmp(keyword, "Throughput")) ppd->throughput = atoi(string); @@ -960,7 +957,7 @@ _ppdOpen( } ppd->fonts = tempfonts; - ppd->fonts[ppd->num_fonts] = _cupsStrAlloc(name); + ppd->fonts[ppd->num_fonts] = strdup(name); ppd->num_fonts ++; } else if (!strncmp(keyword, "ParamCustom", 11)) @@ -1125,7 +1122,7 @@ _ppdOpen( strlcpy(choice->text, text[0] ? text : _("Custom"), sizeof(choice->text)); - choice->code = _cupsStrAlloc(string); + choice->code = strdup(string); if (custom_option->section == PPD_ORDER_JCL) ppd_decode(choice->code); @@ -1327,7 +1324,7 @@ _ppdOpen( option->section = PPD_ORDER_ANY; - _cupsStrFree(string); + free(string); string = NULL; /* @@ -1355,7 +1352,7 @@ _ppdOpen( strlcpy(choice->text, custom_attr->text[0] ? custom_attr->text : _("Custom"), sizeof(choice->text)); - choice->code = _cupsStrRetain(custom_attr->value); + choice->code = strdup(custom_attr->value); } } else if (!strcmp(keyword, "JCLOpenUI")) @@ -1434,7 +1431,7 @@ _ppdOpen( option->section = PPD_ORDER_JCL; group = NULL; - _cupsStrFree(string); + free(string); string = NULL; /* @@ -1458,7 +1455,7 @@ _ppdOpen( strlcpy(choice->text, custom_attr->text[0] ? custom_attr->text : _("Custom"), sizeof(choice->text)); - choice->code = _cupsStrRetain(custom_attr->value); + choice->code = strdup(custom_attr->value); } } else if (!strcmp(keyword, "CloseUI")) @@ -1472,7 +1469,7 @@ _ppdOpen( option = NULL; - _cupsStrFree(string); + free(string); string = NULL; } else if (!strcmp(keyword, "JCLCloseUI")) @@ -1486,7 +1483,7 @@ _ppdOpen( option = NULL; - _cupsStrFree(string); + free(string); string = NULL; } else if (!strcmp(keyword, "OpenGroup")) @@ -1533,14 +1530,14 @@ _ppdOpen( if (group == NULL) goto error; - _cupsStrFree(string); + free(string); string = NULL; } else if (!strcmp(keyword, "CloseGroup")) { group = NULL; - _cupsStrFree(string); + free(string); string = NULL; } else if (!strcmp(keyword, "OrderDependency")) @@ -1598,7 +1595,7 @@ _ppdOpen( option->order = order; } - _cupsStrFree(string); + free(string); string = NULL; } else if (!strncmp(keyword, "Default", 7)) @@ -1841,7 +1838,7 @@ _ppdOpen( * Don't add this one as an attribute... */ - _cupsStrFree(string); + free(string); string = NULL; } else if (!strcmp(keyword, "PaperDimension")) @@ -1863,7 +1860,7 @@ _ppdOpen( size->width = (float)_cupsStrScand(string, &sptr, loc); size->length = (float)_cupsStrScand(sptr, NULL, loc); - _cupsStrFree(string); + free(string); string = NULL; } else if (!strcmp(keyword, "ImageableArea")) @@ -1887,7 +1884,7 @@ _ppdOpen( size->right = (float)_cupsStrScand(sptr, &sptr, loc); size->top = (float)_cupsStrScand(sptr, NULL, loc); - _cupsStrFree(string); + free(string); string = NULL; } else if (option != NULL && @@ -1943,7 +1940,7 @@ _ppdOpen( (mask & (PPD_KEYWORD | PPD_STRING)) == (PPD_KEYWORD | PPD_STRING)) ppd_add_attr(ppd, keyword, name, text, string); else - _cupsStrFree(string); + free(string); } /* @@ -1966,7 +1963,7 @@ _ppdOpen( goto error; } - ppd_free(line.buffer); + free(line.buffer); /* * Reset language preferences... @@ -2048,8 +2045,8 @@ _ppdOpen( error: - _cupsStrFree(string); - ppd_free(line.buffer); + free(string); + free(line.buffer); ppdClose(ppd); @@ -2487,9 +2484,9 @@ ppd_free_filters(ppd_file_t *ppd) /* I - PPD file */ if (ppd->num_filters > 0) { for (i = ppd->num_filters, filter = ppd->filters; i > 0; i --, filter ++) - _cupsStrFree(*filter); + free(*filter); - ppd_free(ppd->filters); + free(ppd->filters); ppd->num_filters = 0; ppd->filters = NULL; @@ -2516,7 +2513,7 @@ ppd_free_group(ppd_group_t *group) /* I - Group to free */ i --, option ++) ppd_free_option(option); - ppd_free(group->options); + free(group->options); } if (group->num_subgroups > 0) @@ -2526,7 +2523,7 @@ ppd_free_group(ppd_group_t *group) /* I - Group to free */ i --, subgroup ++) ppd_free_group(subgroup); - ppd_free(group->subgroups); + free(group->subgroups); } } @@ -2548,10 +2545,10 @@ ppd_free_option(ppd_option_t *option) /* I - Option to free */ i > 0; i --, choice ++) { - _cupsStrFree(choice->code); + free(choice->code); } - ppd_free(option->choices); + free(option->choices); } } @@ -3288,7 +3285,7 @@ ppd_read(cups_file_t *fp, /* I - File to read from */ lineptr ++; } - *string = _cupsStrAlloc(lineptr); + *string = strdup(lineptr); mask |= PPD_STRING; } @@ -3410,7 +3407,7 @@ ppd_update_filters(ppd_file_t *ppd, /* I - PPD file */ filter += ppd->num_filters; ppd->num_filters ++; - *filter = _cupsStrAlloc(buffer); + *filter = strdup(buffer); } while ((attr = ppdFindNextAttr(ppd, "cupsFilter2", NULL)) != NULL); -- 2.39.5