Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 May 2014 17:05:47 GMT
From:      Yasuhito FUTATSUKI <futatuki@yf.bsdclub.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/189618: net/GeoIP: geoipupdate.sh don't update file atomically
Message-ID:  <201405101705.s4AH5l68084989@cgiserv.freebsd.org>
Resent-Message-ID: <201405101710.s4AHA0aI025133@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         189618
>Category:       ports
>Synopsis:       net/GeoIP: geoipupdate.sh don't update file atomically
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 10 17:10:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Yasuhito FUTATSUKI
>Release:        FreeBSD 10.0-RELEASE-p2
>Organization:
DEBUG, a users group of *BSD, in Japan
>Environment:
FreeBSD sv.debug.gr.jp 10.0-RELEASE-p2 FreeBSD 10.0-RELEASE-p2 #0 r29:30: Thu May  1 19:43:20 JST 2014     root@:/usr/obj/usr/src/sys/XEN-IPSEC  amd64
>Description:
geoipupdate.sh provided from net/GeoIP, produced from files/geoipupdate.sh.in,
don't update GeoIP.dat atomically. It clears original file by using shell
redirect (>), then download and gunzip to it.
So, if other process try to use it while updating, the process will see broken data.
>How-To-Repeat:
run /usr/local/bin/geoipupdate.sh as root
>Fix:
fetch GeoIP.dat.gz and gunzip it as filename other than GeoIP.dat in the same file system, then rename(2) to GeoIP.dat.


Patch attached with submission follows:

Index: files/geoipupdate.sh.in
===================================================================
--- files/geoipupdate.sh.in	(revision 353207)
+++ files/geoipupdate.sh.in	(working copy)
@@ -1,2 +1,14 @@
 #!/bin/sh
-fetch -o - http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | gunzip > %%DATADIR%%/GeoIP.dat
+TEMPFILE=`mktemp %%DATADIR%%/GeoIP.dat-XXXXXX`
+if fetch -o - http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | gunzip >> $TEMPFILE ; then
+    chmod og+r $TEMPFILE
+    if ! mv $TEMPFILE %%DATADIR%%/GeoIP.dat ; then
+        rm $TEMPFILE
+        echo fail to substitute GeoIP.dat 
+        exit 2
+    fi
+else
+    rm $TEMPFILE
+    echo fail to update GeoIP.dat
+    exit 1
+fi


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405101705.s4AH5l68084989>