From: Tomas Mraz Date: Fri, 31 Mar 2017 14:25:06 +0000 (+0200) Subject: Fix buffer overflow if NULL line is present in db. X-Git-Tag: 4.5~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F70%2Fhead;p=thirdparty%2Fshadow.git Fix buffer overflow if NULL line is present in db. If ptr->line == NULL for an entry, the first cycle will exit, but the second one will happily write past entries buffer. We actually do not want to exit the first cycle prematurely on ptr->line == NULL. Signed-off-by: Tomas Mraz --- diff --git a/lib/commonio.c b/lib/commonio.c index b10da06a2..31edbaaf3 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -751,16 +751,16 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *)) for (ptr = db->head; (NULL != ptr) #if KEEP_NIS_AT_END - && (NULL != ptr->line) - && ( ('+' != ptr->line[0]) - && ('-' != ptr->line[0])) + && ((NULL == ptr->line) + || (('+' != ptr->line[0]) + && ('-' != ptr->line[0]))) #endif ; ptr = ptr->next) { n++; } #if KEEP_NIS_AT_END - if ((NULL != ptr) && (NULL != ptr->line)) { + if (NULL != ptr) { nis = ptr; } #endif