[hunspell] Resolves: rhbz#759647 temp file name collision

Caolán McNamara caolanm at fedoraproject.org
Tue Dec 6 22:53:11 UTC 2011


commit 5465ec7811f5f5b702102bf81d351a38ec843ca0
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Dec 6 22:52:53 2011 +0000

    Resolves: rhbz#759647 temp file name collision

 hunspell.rhbz759647.patch |   74 +++++++++++++++++++++++++++++++++++++++++++++
 hunspell.spec             |    7 ++++-
 2 files changed, 80 insertions(+), 1 deletions(-)
---
diff --git a/hunspell.rhbz759647.patch b/hunspell.rhbz759647.patch
new file mode 100644
index 0000000..31f48ce
--- /dev/null
+++ b/hunspell.rhbz759647.patch
@@ -0,0 +1,74 @@
+Index: src/tools/hunspell.cxx
+===================================================================
+RCS file: /cvsroot/hunspell/hunspell/src/tools/hunspell.cxx,v
+retrieving revision 1.28
+diff -u -r1.28 hunspell.cxx
+--- src/tools/hunspell.cxx	21 Jan 2011 17:30:41 -0000	1.28
++++ src/tools/hunspell.cxx	6 Dec 2011 22:44:15 -0000
+@@ -128,8 +128,6 @@
+ #define readline scanline
+ #endif
+ 
+-#define TEMPNAME "hunSPELL.bak"
+-
+ extern char * mystrdup(const char * s);
+ 
+ // file formats:
+@@ -1316,14 +1314,12 @@
+     char * extension = basename(filename, '.');
+     parser = get_parser(format, extension, pMS[0]);
+ 
+-    char * tempname = (char *) malloc(strlen(filename) + strlen(TEMPNAME) + 1);
+-    strcpy(tempname, filename);
+-    strcpy(basename(tempname, DIRSEPCH), TEMPNAME);
+-    
+-    FILE *tempfile;
++   
++    FILE *tempfile = tmpfile();
+ 
+-    if (!(tempfile = fopen(tempname, "w"))) {
+-        fprintf(stderr, gettext("Can't create tempfile %s.\n"), tempname);
++    if (!tempfile)
++    {
++        perror(gettext("Can't create tempfile"));
+         endwin();
+         exit(1);
+     }
+@@ -1337,7 +1333,7 @@
+ 		    case -1: {
+ 			clear();
+ 			refresh();
+-			unlink(tempname);
++			fclose(tempfile); //automatically deleted when closed
+ 			endwin();
+ 			exit(0);
+ 		    }
+@@ -1350,15 +1346,22 @@
+ 	    }
+ 	}
+ 	fclose(text);
+-	fclose(tempfile);
+ 	delete parser;
+ 
+-	if (! modified) {
+-	    unlink(tempname);
+-	} else {
+-            rename(tempname, filename);
++	if (modified) {
++		rewind(tempfile);
++		text = fopen(filename, "wb");
++
++		size_t n;
++		while ((n = fread(buf, 1, MAXLNLEN, tempfile)) > 0)
++		{
++			if (fwrite(buf, 1, n, text) != n)
++				perror("write failed");
++		}
++
++		fclose(text);
+ 	}
+-        free(tempname);
++	fclose(tempfile); //automatically deleted when closed
+ }
+ 
+ #endif
diff --git a/hunspell.spec b/hunspell.spec
index b16a49a..bc1d305 100644
--- a/hunspell.spec
+++ b/hunspell.spec
@@ -3,7 +3,7 @@
 Name:      hunspell
 Summary:   A spell checker and morphological analyzer library
 Version:   1.3.2
-Release:   1%{?dist}
+Release:   2%{?dist}
 Source:    http://downloads.sourceforge.net/%{name}/hunspell-%{version}.tar.gz
 Group:     System Environment/Libraries
 URL:       http://hunspell.sourceforge.net/
@@ -16,6 +16,7 @@ BuildRequires: valgrind
 %if %{double_profiling_build}
 BuildRequires: words
 %endif
+Patch0: hunspell.rhbz759647.patch
 
 %description
 Hunspell is a spell checker and morphological analyzer library and program 
@@ -33,6 +34,7 @@ Includes and definitions for developing with hunspell
 
 %prep
 %setup -q
+%patch0 -p0 -b .rhbz759647
 
 %build
 configureflags="--disable-rpath --disable-static --with-ui --with-readline"
@@ -121,6 +123,9 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man3/hunspell.3.gz
 
 %changelog
+* Tue Dec 06 2011 Caolán McNamara <caolanm at redhat.com> - 1.3.2-2
+- Resolves: rhbz#759647 temp file name collision
+
 * Tue May 24 2011 Caolán McNamara <caolanm at redhat.com> - 1.3.2-1
 - Resolves: rhbz#706686 latest version
 


More information about the scm-commits mailing list