Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Dec 2016 17:10:41 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r310608 - head/libexec/talkd
Message-ID:  <201612261710.uBQHAfse009807@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Dec 26 17:10:41 2016
New Revision: 310608
URL: https://svnweb.freebsd.org/changeset/base/310608

Log:
  Avoid use after free.
  
  Reported by:	Clang static code analyzer
  MFC after:	2 weeks

Modified:
  head/libexec/talkd/table.c

Modified: head/libexec/talkd/table.c
==============================================================================
--- head/libexec/talkd/table.c	Mon Dec 26 16:45:00 2016	(r310607)
+++ head/libexec/talkd/table.c	Mon Dec 26 17:10:41 2016	(r310608)
@@ -82,14 +82,15 @@ static TABLE_ENTRY *table = NIL;
 CTL_MSG *
 find_match(CTL_MSG *request)
 {
-	TABLE_ENTRY *ptr;
+	TABLE_ENTRY *ptr, *next;
 	time_t current_time;
 
 	gettimeofday(&tp, NULL);
 	current_time = tp.tv_sec;
 	if (debug)
 		print_request("find_match", request);
-	for (ptr = table; ptr != NIL; ptr = ptr->next) {
+	for (ptr = table; ptr != NIL; ptr = next) {
+		next = ptr->next;
 		if ((ptr->time - current_time) > MAX_LIFE) {
 			/* the entry is too old */
 			if (debug)
@@ -115,7 +116,7 @@ find_match(CTL_MSG *request)
 CTL_MSG *
 find_request(CTL_MSG *request)
 {
-	TABLE_ENTRY *ptr;
+	TABLE_ENTRY *ptr, *next;
 	time_t current_time;
 
 	gettimeofday(&tp, NULL);
@@ -126,7 +127,8 @@ find_request(CTL_MSG *request)
 	 */
 	if (debug)
 		print_request("find_request", request);
-	for (ptr = table; ptr != NIL; ptr = ptr->next) {
+	for (ptr = table; ptr != NIL; ptr = next) {
+		next = ptr->next;
 		if ((ptr->time - current_time) > MAX_LIFE) {
 			/* the entry is too old */
 			if (debug)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201612261710.uBQHAfse009807>