ports/189618: net/GeoIP: geoipupdate.sh don't update file atomically

Yasuhito FUTATSUKI futatuki at yf.bsdclub.org
Sat May 10 17:10:01 UTC 2014


>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:


More information about the freebsd-ports-bugs mailing list