]> git.saurik.com Git - apt.git/commitdiff
Base256ToNum: Fix uninitialized value
authorJulian Andres Klode <jak@debian.org>
Wed, 31 Aug 2016 15:18:07 +0000 (17:18 +0200)
committerJulian Andres Klode <jak@debian.org>
Wed, 5 Oct 2016 19:53:38 +0000 (21:53 +0200)
If the inner Base256ToNum() returned false, it did not set
Num to a new value, causing it to be uninitialized, and thus
might have caused the function to exit despite a good result.

Also document why the Res = Num, if (Res != Num) magic is done.

Reported-By: valgrind
(cherry picked from commit cf7503d8a09ebce695423fdeb2402c456c18f3d8)

apt-pkg/contrib/strutl.cc

index ebde6b20daad3780289695e85dd066c03c60be49..26e303263deb6c21cbd08729ef6d4a5697bbdbbe 100644 (file)
@@ -1090,10 +1090,11 @@ bool Base256ToNum(const char *Str,unsigned long long &Res,unsigned int Len)
    tar files */
 bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len)
 {
-   unsigned long long Num;
+   unsigned long long Num = 0;
    bool rc;
 
    rc = Base256ToNum(Str, Num, Len);
+   // rudimentary check for overflow (Res = ulong, Num = ulonglong)
    Res = Num;
    if (Res != Num)
       return false;