From 606df517f0aecafd32a45fe981321d5aea35f4c8 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Mon, 6 Aug 2012 17:12:38 -0600 Subject: [PATCH] dtprintinfo: Fix SIGSEGV in dtprintinfo (passing NULL as first argument to catgets). Patch from Douglas Mencken : The issue is that MESSAGE tries to invoke catgets with NULL first parameter, which is dereferenced inside catgets (Std C Library function) without checking, from catgets.c source: if (catalog->name_ptr[idx + 0] == (u_int32_t) set && catalog->name_ptr[idx + 1] == (u_int32_t) message) On the other hand, there's a special value: -1 (cast to nl_catd), which must be used instead of 0 (NULL) in the case when we are unable to provide real catalog_desc, from catgets.c source: /* Be generous if catalog which failed to be open is used. */ if (catalog_desc == (nl_catd) -1 || ++set <= 0 || message < 0) return (char *) string; --- cde/programs/dtprintinfo/DtPrintinfo.C | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cde/programs/dtprintinfo/DtPrintinfo.C b/cde/programs/dtprintinfo/DtPrintinfo.C index 065c8af8..ac780a08 100644 --- a/cde/programs/dtprintinfo/DtPrintinfo.C +++ b/cde/programs/dtprintinfo/DtPrintinfo.C @@ -94,14 +94,18 @@ int main(int argc, char **argv) dtprintinfo_cat = catopen("dtprintinfo", 0); #endif - if ((nl_catd) errno || dtprintinfo_cat == (nl_catd) -1) - dtprintinfo_cat = NULL; + if ((nl_catd) errno) + dtprintinfo_cat = (nl_catd) -1; #ifdef hpux else msg_strings = (char **)calloc(LAST_MSG_NO, sizeof(char *)); #endif } + if (dtprintinfo_cat == NULL) { + dtprintinfo_cat = (nl_catd) -1; + } + if (!STRCMP(argv[1], "-help")) { char *output; -- 2.25.1