From 472e55bcd262ab3ae963f28b8e2b22c53ab72e2b Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 9 Jun 2007 12:53:41 +0000 Subject: [PATCH] Fix Savannah bug #19980, by avoiding the non-POSIX function putw() (and in previous changes, getw(), and wcwidth()) --- ChangeLog | 10 ++++++++++ NEWS | 4 ++++ locate/Makefile.am | 1 + locate/code.c | 15 +++++++++------ locate/frcode.c | 3 +++ locate/locate.c | 3 +++ locate/locatedb.h | 5 +++-- locate/word_io.c | 27 +++++++++++++++++++++++++++ 8 files changed, 60 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index fbe6828..e56c1e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2007-06-09 James Youngman + + Avoid using the non-portable function putw(). + * locate/locatedb.h: Declare putword(). + * locate/frcode.c: Include as locatedb.h now requires + it. + * locate/code.c (main): Use putword() rather than putw(), because + the latter was removed from SUSv3. This fixes Savannah bug #19980. + Also include as locatedb.h now requires this. + * locate/word_io.c (putword): Define the new function putword. + Ensure that is included before any system header * find/defs.h: Do not include from "defs.h". Instead just complain if it was not already included, since it needs to diff --git a/NEWS b/NEWS index 1682345..3ed5226 100644 --- a/NEWS +++ b/NEWS @@ -35,6 +35,10 @@ This bug has been assigned CVE number CVE-2007-2452. #19981: Don't call setgroups if the function isn't available. This fixes Savannah bug# 19981. +#19980: Don't use the functions putw() or getw() since these are not +in current POSIX. Use the gnulib version of wcwidth() where the +system does not provide it. + * Major changes in release 4.3.6 ** Bug Fixes diff --git a/locate/Makefile.am b/locate/Makefile.am index 1112371..7466ed3 100644 --- a/locate/Makefile.am +++ b/locate/Makefile.am @@ -12,6 +12,7 @@ BUILT_SOURCES = dblocation.texi EXTRA_DIST = locatedb.h updatedb.sh $(man_MANS) CLEANFILES = updatedb dblocation.texi locate_SOURCES = locate.c word_io.c +code_SOURCES = code.c word_io.c INCLUDES = -I$(top_srcdir)/lib -I../gnulib/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCATE_DB=\"$(LOCATE_DB)\" -DLOCALEDIR=\"$(localedir)\" diff --git a/locate/code.c b/locate/code.c index aab4139..a00f635 100644 --- a/locate/code.c +++ b/locate/code.c @@ -1,5 +1,5 @@ /* code -- bigram- and front-encode filenames for locate - Copyright (C) 1994 Free Software Foundation, Inc. + Copyright (C) 1994, 2005, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,6 +50,7 @@ #include #include #include +#include #ifdef STDC_HEADERS @@ -239,15 +240,17 @@ main (int argc, char **argv) if (diffcount < -LOCATEDB_OLD_OFFSET || diffcount > LOCATEDB_OLD_OFFSET) { if (EOF ==- putc (LOCATEDB_OLD_ESCAPE, stdout)) - outerr(); - - if (EOF == putw (diffcount + LOCATEDB_OLD_OFFSET, stdout)) - outerr(); + outerr (); + + if (!putword (stdout, + diffcount+LOCATEDB_OLD_OFFSET, + GetwordEndianStateNative)) + outerr (); } else { if (EOF == putc (diffcount + LOCATEDB_OLD_OFFSET, stdout)) - outerr(); + outerr (); } /* Look for bigrams in the remainder of the path. */ diff --git a/locate/frcode.c b/locate/frcode.c index 45a102a..0cd40dc 100644 --- a/locate/frcode.c +++ b/locate/frcode.c @@ -65,11 +65,14 @@ */ #include + + #include #include #include #include #include +#include #if defined(HAVE_STRING_H) || defined(STDC_HEADERS) #include diff --git a/locate/locate.c b/locate/locate.c index 7f66991..46d5595 100644 --- a/locate/locate.c +++ b/locate/locate.c @@ -61,6 +61,7 @@ */ #include + #include #include #include @@ -72,6 +73,8 @@ #include #include +#include /* for bool/boolean */ + /* The presence of unistd.h is assumed by gnulib these days, so we * might as well assume it too. */ diff --git a/locate/locatedb.h b/locate/locatedb.h index 8423317..42cede8 100644 --- a/locate/locatedb.h +++ b/locate/locatedb.h @@ -20,8 +20,6 @@ #ifndef _LOCATEDB_H #define _LOCATEDB_H 1 -#include - /* The magic string at the start of a locate database, to make sure it's in the right format. The 02 is the database format version number. This string has the same format as a database entry, but you can't @@ -75,6 +73,9 @@ int getword (FILE *fp, const char *filename, size_t minvalue, size_t maxvalue, GetwordEndianState *endian_state_flag); +bool putword (FILE *fp, int word, + GetwordEndianState endian_state_flag); + #define SLOCATE_DB_MAGIC_LEN 2 diff --git a/locate/word_io.c b/locate/word_io.c index df42b6f..9e44957 100644 --- a/locate/word_io.c +++ b/locate/word_io.c @@ -18,8 +18,12 @@ */ #include + #include +#include #include +#include /* for bool */ +#include #include "quote.h" #include "quotearg.h" @@ -147,3 +151,26 @@ getword (FILE *fp, } } + +bool +putword (FILE *fp, int word, + GetwordEndianState endian_state_flag) +{ + size_t items_written; + + /* You must decide before calling this function which + * endianness you want to use. + */ + assert(endian_state_flag != GetwordEndianStateInitial); + if (GetwordEndianStateSwab == endian_state_flag) + { + word = bswap_32(word); + } + + items_written = fwrite(&word, sizeof(word), 1, fp); + if (1 == items_written) + return true; + else + return false; +} + -- 2.11.4.GIT