Bug 22553 - Memory-Leaks und NPE in univention-policy
Memory-Leaks und NPE in univention-policy
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UMC - Policies
UCS 3.0
Other Linux
: P5 normal (vote)
: UCS 3.0 - MS2
Assigned To: Philipp Hahn
Andreas Büsching
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-17 19:41 CEST by Philipp Hahn
Modified: 2011-12-13 15:47 CET (History)
1 user (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments
Fix leaks, NPE, (13.00 KB, patch)
2011-05-17 19:41 CEST, Philipp Hahn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2011-05-17 19:41:55 CEST
Created attachment 3281 [details]
Fix leaks, NPE, 

+  * Fix memory leaks and NULL pointer exceptions.
+  * Simplify allocating and cleaning memory.
+  * Handle line terminattion in ldap.secret.
+  * Make univention_krb5_init() thread-save.
Comment 1 Philipp Hahn univentionstaff 2011-05-20 07:39:48 CEST
univention-policy hatte noch etliche Memory-Leaks mehr, von denen jetzt zumindest noch noch ein internes Speicherleck in libldap vorhanden ist:

$ libtool --mode=execute valgrind  --leak-check=full --show-reachable=yes tools/univention_policy_result "cn=mem92,cn=computers,dc=univention,dc=qa"
==10821== Warning: invalid file descriptor -1 in syscall close()
==10821== 
==10821== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 36 from 1)
==10821== malloc/free: in use at exit: 20 bytes in 1 blocks.
==10821== malloc/free: 1,017 allocs, 1,016 frees, 124,061 bytes allocated.
==10821== For counts of detected errors, rerun with: -v
==10821== searching for pointers to 1 not-freed blocks.
==10821== checked 269,084 bytes.
==10821== 
==10821== 20 bytes in 1 blocks are still reachable in loss record 1 of 1
==10821==    at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==10821==    by 0x41CEFFF: ber_memalloc_x (in /usr/lib/liblber-2.4.so.2.5.6)
==10821==    by 0x41CF13D: ber_strdup_x (in /usr/lib/liblber-2.4.so.2.5.6)
==10821==    by 0x41AB630: (within /usr/lib/libldap_r-2.4.so.2.5.6)
==10821==    by 0x41ABBAB: ldap_int_initialize (in /usr/lib/libldap_r-2.4.so.2.5.6)
==10821==    by 0x418E169: ldap_create (in /usr/lib/libldap_r-2.4.so.2.5.6)
==10821==    by 0x418E8AD: ldap_initialize (in /usr/lib/libldap_r-2.4.so.2.5.6)
==10821==    by 0x4029FD4: univention_ldap_open (ldap.c:233)
==10821==    by 0x8048CBE: main (univention_policy_result.c:119)
==10821== 
==10821== LEAK SUMMARY:
==10821==    definitely lost: 0 bytes in 0 blocks.
==10821==      possibly lost: 0 bytes in 0 blocks.
==10821==    still reachable: 20 bytes in 1 blocks.
==10821==         suppressed: 0 bytes in 0 blocks.

Bei der Fehlersuche wurden etliche Funktionen umgeschrieben und die Funktionalität zum Freigeben der verschiedenen Strukturen in eigene Funktionen ausgelagert. Dabei wurden auch einige nicht-öffentliche Funktionen aus dem Header-File entfernt und in C-Quelltext als "static" markiert. Ein "grep" über die DHCPd- und Bind-Patches hat jedenfalls keine externen Verwender angezeigt, zumal viele dieser Funktionen auch nichteinmal im Header-File ihre Signatur hatten.

svn24355, univention-policy_5.0.1-1.84.201105191633

ChangeLog:
\item Several memroy leaks in \ucsName{univention-policy} have been fixed (\ucsBug{22553}).
Comment 2 Philipp Hahn univentionstaff 2011-09-16 17:45:28 CEST
Durch svn24355 wurde ein Fehler eingebaut: object_classes wurde innerhalb der Schleife freigegeben, so das beim Aufsteigen im LDAP-Baum dann keine objectClassess mehr an univention_policy_merge() übergeben wurden. Das hat dazu geführt, das die Attribute nicht an ihren zugehörigen Policy-Klassen notiert wurden, sondern (in diesem Fall) an univentionObject.

Mit "univention_policy_result -D `ucr get ldap/hostdn` -y /etc/machine.secret `ucr get ldap/hostdn`" war das nicht zu erkennen, aber beim isc-dhcp-Server fiel das auf, weil dort keinerlei durch Policies vorgegebene Attribute mehr gesetzt wurden.

svn26875, univention-policy_5.0.6-1.90.201109161738

ChangeLog: ±0
Comment 3 Andreas Büsching univentionstaff 2011-09-22 16:49:43 CEST
ich würde sagen das ist in Ordnung

root@master:~# valgrind --leak-check=full --show-reachable=yes univention-policy-result -D $ldap_hostdn -y /etc/machine.secret cn=slave1,cn=computers,dc=ucs3,dc=test >/dev/null
==9839== Memcheck, a memory error detector
==9839== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==9839== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==9839== Command: univention-policy-result -D cn=master,cn=dc,cn=computers,dc=ucs3,dc=test -y /etc/machine.secret cn=slave1,cn=computers,dc=ucs3,dc=test
==9839== 
==9839== Conditional jump or move depends on uninitialised value(s)
==9839==    at 0x40250C7: strlen (mc_replace_strmem.c:282)
==9839==    by 0x40387D2: univention_ldap_open (in /usr/lib/libuniventionpolicy.so.0.0.1)
==9839==    by 0x8049007: ??? (in /usr/bin/univention_policy_result)
==9839==    by 0x4052C75: (below main) (libc-start.c:228)
==9839== 
==9839== Conditional jump or move depends on uninitialised value(s)
==9839==    at 0x40384C0: univention_ldap_close (in /usr/lib/libuniventionpolicy.so.0.0.1)
==9839==    by 0x8049026: ??? (in /usr/bin/univention_policy_result)
==9839==    by 0x4052C75: (below main) (libc-start.c:228)
==9839== 
==9839== 
==9839== HEAP SUMMARY:
==9839==     in use at exit: 16 bytes in 1 blocks
==9839==   total heap usage: 640 allocs, 639 frees, 108,866 bytes allocated
==9839== 
==9839== 16 bytes in 1 blocks are still reachable in loss record 1 of 1
==9839==    at 0x4023F50: malloc (vg_replace_malloc.c:236)
==9839==    by 0x41D4DA6: ber_memalloc_x (in /usr/lib/liblber-2.4.so.2.7.0)
==9839==    by 0x41D4EFD: ber_strdup_x (in /usr/lib/liblber-2.4.so.2.7.0)
==9839==    by 0x41B0840: ??? (in /usr/lib/libldap_r-2.4.so.2.7.0)
==9839==    by 0x41B0E28: ldap_int_initialize (in /usr/lib/libldap_r-2.4.so.2.7.0)
==9839==    by 0x41936E8: ldap_create (in /usr/lib/libldap_r-2.4.so.2.7.0)
==9839==    by 0x4193F4D: ldap_initialize (in /usr/lib/libldap_r-2.4.so.2.7.0)
==9839==    by 0x4038991: univention_ldap_open (in /usr/lib/libuniventionpolicy.so.0.0.1)
==9839==    by 0x8049007: ??? (in /usr/bin/univention_policy_result)
==9839==    by 0x4052C75: (below main) (libc-start.c:228)
==9839== 
==9839== LEAK SUMMARY:
==9839==    definitely lost: 0 bytes in 0 blocks
==9839==    indirectly lost: 0 bytes in 0 blocks
==9839==      possibly lost: 0 bytes in 0 blocks
==9839==    still reachable: 16 bytes in 1 blocks
==9839==         suppressed: 0 bytes in 0 blocks
==9839== 
==9839== For counts of detected and suppressed errors, rerun with: -v
==9839== Use --track-origins=yes to see where uninitialised values come from
==9839== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 36 from 7)
Comment 4 Sönke Schwardt-Krummrich univentionstaff 2011-12-13 15:41:46 CET
UCS 3.0-0 wurde veröffentlicht. Sollte der hier beschriebene Bug mit einer
neueren Version von UCS erneut auftreten, so sollte dieser Bug dupliziert werden:
"Clone This Bug"