strrchr() family considered harmful, part 666
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 21 Sep 2010 10:29:01 +0000 (13:29 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 21 Sep 2010 10:29:01 +0000 (13:29 +0300)
- strrchr() was silently casting away a const on a string coming
  from rpmtdGetString(). Add an explicit cast and warning/fixme commentary
  to the compressFilelist() hack which modifies (and then restores) the
  const string.

lib/legacy.c

index e4a308f..9a065dc 100644 (file)
@@ -63,12 +63,18 @@ static void compressFilelist(Header h)
        }
     }
 
+    /* 
+     * XXX EVIL HACK, FIXME:
+     * This modifies (and then restores) a const string from rpmtd
+     * through basename retrieved from strrchr() which silently 
+     * casts away const on return.
+     */
     while ((i = rpmtdNext(&fileNames)) >= 0) {
        char ** needle;
        char savechar;
        char * baseName;
        size_t len;
-       const char *filename = rpmtdGetString(&fileNames);
+       char *filename = (char *) rpmtdGetString(&fileNames); /* HACK HACK */
 
        if (filename == NULL)   /* XXX can't happen */
            continue;