[csw-devel] SF.net SVN: gar:[20803] csw/mgar/gar/v2/lib/python/rest.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Apr 18 17:18:51 CEST 2013


Revision: 20803
          http://gar.svn.sourceforge.net/gar/?rev=20803&view=rev
Author:   wahwah
Date:     2013-04-18 15:18:51 +0000 (Thu, 18 Apr 2013)
Log Message:
-----------
pkgdb: Validate md5 sums in RestClient

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/rest.py

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2013-04-18 15:18:40 UTC (rev 20802)
+++ csw/mgar/gar/v2/lib/python/rest.py	2013-04-18 15:18:51 UTC (rev 20803)
@@ -6,6 +6,7 @@
 import logging
 import os
 import pycurl
+import re
 import urllib2
 
 DEFAULT_URL = "http://buildfarm.opencsw.org"
@@ -34,7 +35,12 @@
     self.password = password
     self.debug = debug
 
+  def ValidateMd5(self, md5_sum):
+    if not re.match(r'^[0-9a-f]{32}$', md5_sum):
+      raise ArgumentError('Passed argument is not a valid md5 sum: %r' % md5_sum)
+
   def GetPkgByMd5(self, md5_sum):
+    self.ValidateMd5(md5_sum)
     url = self.rest_url + self.PKGDB_APP + "/srv4/%s/" % md5_sum
     logging.debug("GetPkgByMd5(): GET %s", url)
     try:
@@ -51,6 +57,7 @@
         raise
 
   def GetPkgstatsByMd5(self, md5_sum):
+    self.ValidateMd5(md5_sum)
     url = self.rest_url + self.PKGDB_APP + "/srv4/%s/pkg-stats/" % md5_sum
     logging.debug("GetPkgstatsByMd5(): GET %s", url)
     try:
@@ -67,6 +74,7 @@
         raise
 
   def GetMaintainerByMd5(self, md5_sum):
+    self.ValidateMd5(md5_sum)
     pkg = self.GetPkgByMd5(md5_sum)
     if not pkg:
       pkg = {"maintainer_email": "Unknown"}

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list