Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:06:29 -0000
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r346002 - head/stand/common
Message-ID:  <201904071220.x37CKHeP001203@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tsoome
Date: Sun Apr  7 12:20:17 2019
New Revision: 346002
URL: https://svnweb.freebsd.org/changeset/base/346002

Log:
  loader: mod_loadkld() error: we previously assumed 'last_file' could be null
  
  The last_file variable is used to reset the loadaddr variable back to original
  value; however, it is possible the last_file is NULL, so we can not blindly
  trust it. But then again, we can just save the original loadaddr and use
  the saved value for recovery.
  
  MFC after:	1w

Modified:
  head/stand/common/module.c

Modified: head/stand/common/module.c
==============================================================================
--- head/stand/common/module.c	Sun Apr  7 12:10:19 2019	(r346001)
+++ head/stand/common/module.c	Sun Apr  7 12:20:17 2019	(r346002)
@@ -559,9 +559,10 @@ mod_load(char *modname, struct mod_depend *verinfo, in
 int
 mod_loadkld(const char *kldname, int argc, char *argv[])
 {
-	struct preloaded_file	*fp, *last_file;
-	int				err;
+	struct preloaded_file	*fp;
+	int			err;
 	char			*filename;
+	vm_offset_t		loadaddr_saved;
 
 	/*
 	 * Get fully qualified KLD name
@@ -582,22 +583,19 @@ mod_loadkld(const char *kldname, int argc, char *argv[
 		free(filename);
 		return (0);
 	}
-	for (last_file = preloaded_files;
-	     last_file != NULL && last_file->f_next != NULL;
-	     last_file = last_file->f_next)
-		;
 
 	do {
 		err = file_load(filename, loadaddr, &fp);
 		if (err)
 			break;
 		fp->f_args = unargv(argc, argv);
+		loadaddr_saved = loadaddr;
 		loadaddr = fp->f_addr + fp->f_size;
 		file_insert_tail(fp);		/* Add to the list of loaded files */
 		if (file_load_dependencies(fp) != 0) {
 			err = ENOENT;
 			last_file->f_next = NULL;
-			loadaddr = last_file->f_addr + last_file->f_size;
+			loadaddr = loadaddr_saved;
 			fp = NULL;
 			break;
 		}





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