[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#190937: anna: Patch



Package: anna
Version: 0.026, HEAD (not installed)
Tags: patch
Followup-For: Bug #190937

Enclosed is a patch for this issue. There are a few notes about it. The
first is that the internal numbering scheme for anna.c is inconsistent.
It appears that each error return was meant to be unique within the
whole of the source file (numbered 1-x) but there are inconsistencies
in this scheme. As such, there is an error code that now duplicates
within the whole of the source file, but not within the function that
returns it, so it should be Ok unless you implement a standard error
code checker function. But in this case, you'll have to fix the
numbering scheme anyhow.

The other issue is that the functions simply return out if asprintf
returns an error. While this isn't ideal, if you're dealing with such a
low memory situation that you can't allocate a string, you've probably
got bigger issues. Nonetheless, if you want better error handling, let
me know and I'll see what I can do.

 - David

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux polymerase 2.4.20 #1 Tue Dec 17 00:00:32 PST 2002 i686
Locale: LANG=C, LC_CTYPE=C

diff -ur anna/anna.c annapatch/anna.c
--- anna/anna.c	2003-05-06 20:48:21.000000000 -0700
+++ annapatch/anna.c	2003-05-06 20:46:53.000000000 -0700
@@ -28,7 +28,8 @@
         struct package_t *p;
 
         if (defval != NULL && (p = di_pkg_find(ret_pkgs, defval))) {
-            asprintf(&defval, "%s: %s", p->package, p->description);
+            if (asprintf(&defval, "%s: %s", p->package, p->description) == -1)
+	        return 3;
             debconf->command(debconf, "SET", ANNA_RETRIEVER, defval, NULL);
             free(defval);
         }
@@ -225,7 +226,8 @@
             for(f = fp = p->filename; *fp != 0; fp++)
                 if (*fp == '/')
                     f = ++fp;
-            asprintf(&dest_file, "%s/%s", DOWNLOAD_DIR, f);
+            if (asprintf(&dest_file, "%s/%s", DOWNLOAD_DIR, f) == -1) 
+		    return 5;
 
             debconf->command(debconf, "SUBST", "anna/progress_step_retr", "PACKAGE", p->package, NULL);
             debconf->command(debconf, "SUBST", "anna/progress_step_inst", "PACKAGE", p->package, NULL);
diff -ur anna/util.c annapatch/util.c
--- anna/util.c	2003-05-06 20:48:49.000000000 -0700
+++ annapatch/util.c	2003-05-06 20:46:53.000000000 -0700
@@ -127,7 +127,8 @@
         colon_p = strchr(debconf->value, ':');
     if (colon_p != NULL) {
         *colon_p = '\0';
-        asprintf(&retriever, "%s/%s", RETRIEVER_DIR, debconf->value);
+        if (asprintf(&retriever, "%s/%s", RETRIEVER_DIR, debconf->value) == -1)
+	    retriever = NULL;
     }
     return retriever;
 }
@@ -140,7 +141,8 @@
     int ret;
 
     retriever = get_retriever();
-    asprintf(&command, "%s config", retriever);
+    if (asprintf(&command, "%s config", retriever) == -1)
+        return 1;
     ret = system(command);
     free(command);
     return ret;
@@ -154,8 +156,9 @@
     int ret;
 
     retriever = get_retriever();
-    asprintf(&command, "%s packages " DOWNLOAD_DIR "/Packages%s %s %s",
-            retriever, ext, ext[0] == '\0' ? "." : ext, suite);
+    if (asprintf(&command, "%s packages " DOWNLOAD_DIR "/Packages%s %s %s",
+            retriever, ext, ext[0] == '\0' ? "." : ext, suite) == -1)
+        return 1;
     ret = system(command);
     free(command);
     if (ret != 0) {
@@ -166,10 +169,12 @@
             debconf = debconfclient_new();
         debconf->command(debconf, "GET", "mirror/distribution", NULL);
         dist = debconf->value;
-        asprintf(&file, "dists/%s/%s/debian-installer/binary-%s/Packages%s",
-                dist, suite, ARCH, ext);
-        asprintf(&command, "%s retrieve %s " DOWNLOAD_DIR "/Packages%s",
-                retriever, file, ext);
+        if (asprintf(&file, "dists/%s/%s/debian-installer/binary-%s/Packages%s",
+                dist, suite, ARCH, ext) == -1)
+	    return 1;
+        if (asprintf(&command, "%s retrieve %s " DOWNLOAD_DIR "/Packages%s",
+                retriever, file, ext) == -1)
+	    return 1;
         free(file);
         ret = system(command);
         free(command);
@@ -278,7 +283,8 @@
     char *command;
 
     retriever = get_retriever();
-    asprintf(&command, "%s retrieve %s %s", retriever, package->filename, dest);
+    if (asprintf(&command, "%s retrieve %s %s", retriever, package->filename, dest) == -1)
+       return 1;
     ret = !system(command);
     free(retriever);
     free(command);
@@ -292,7 +298,8 @@
     char *command;
     int ret;
 
-    asprintf(&command, "%s %s", DPKG_UNPACK_COMMAND, pkgfile);
+    if (asprintf(&command, "%s %s", DPKG_UNPACK_COMMAND, pkgfile) == -1)
+        return 1;
     ret = !system(command);
     free(command);
     return ret;
@@ -332,10 +339,11 @@
     char *command;
 
     retriever = get_retriever();
-    asprintf(&command, "%s cleanup", retriever);
-    system(command);
+    if (asprintf(&command, "%s cleanup", retriever) != -1) {
+        system(command);
+        free(command);
+    }
     free(retriever);
-    free(command);
 }
 
 /* 

Reply to: