Package: gnuvd
Version: 1.0.3-1.2
Followup-For: Bug #235819

I decided to fix this bug. The problem was that the url was not properly
encoded.

Patch attached.

-- System Information:
Debian Release: 4.0
  APT prefers testing
  APT policy: (900, 'testing'), (20, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/dash
Kernel: Linux 2.6.20
Locale: LANG=C, LC_CTYPE=C (charmap=UTF-8) (ignored: LC_ALL set to nl_NL.utf8)

Versions of packages gnuvd depends on:
ii  libc6                       2.3.6.ds1-13 GNU C Library: Shared libraries

gnuvd recommends no packages.

-- no debconf information
--- gnuvd.c	2007-04-03 14:19:17.000000000 +0200
+++ gnuvd.c++	2007-04-03 14:23:03.000000000 +0200
@@ -299,9 +299,27 @@
 static char*
 vd_construct_http_query (const char *search_term, VDError *ex)
 {
-	char *query;
-	int len= strlen(HTTP_PROXY_HOST ? HTTP_REQUEST_PROXY : HTTP_REQUEST) + 
-		strlen(search_term) * 2;
+	char *query, *encoded_search_term, *pos;
+	int len, i;
+
+	/* The worst that can happen is that all chars need encoding */
+	encoded_search_term = 
+	    (char *) malloc((3 * strlen(search_term) + 1) * sizeof(char));
+	pos = encoded_search_term;
+
+	if (!pos) {
+		*ex = VD_ERR_MEM;
+		return NULL;
+	}
+
+	for (i=0; i<strlen(search_term); i++) 
+		if (isalnum(search_term[i])) 
+			*(pos++) = search_term[i];
+		 else 
+			pos += sprintf(pos, "%%%2x", search_term[i]);
+	
+	len = strlen(HTTP_PROXY_HOST ? HTTP_REQUEST_PROXY : HTTP_REQUEST) + 
+		strlen(encoded_search_term) * 2;
 	
 	query = (char*) malloc (len + 1);
 	if (!query) {
@@ -310,8 +328,10 @@
 	}	
 	
 	snprintf (query, len, (HTTP_PROXY_HOST ? HTTP_REQUEST_PROXY : HTTP_REQUEST),
-		  search_term,search_term);
-	
+		  encoded_search_term,encoded_search_term);
+
+	free(encoded_search_term);
+
 	return query;
 }
 

Reply via email to