From owner-svn-src-all@FreeBSD.ORG Tue May 4 04:04:37 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C49E4106564A; Tue, 4 May 2010 04:04:37 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id B28498FC14; Tue, 4 May 2010 04:04:37 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4444bA2094949; Tue, 4 May 2010 04:04:37 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4444bRM094947; Tue, 4 May 2010 04:04:37 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201005040404.o4444bRM094947@svn.freebsd.org> From: Warner Losh Date: Tue, 4 May 2010 04:04:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207595 - stable/7/usr.sbin/config X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 May 2010 04:04:37 -0000 Author: imp Date: Tue May 4 04:04:37 2010 New Revision: 207595 URL: http://svn.freebsd.org/changeset/base/207595 Log: MFC r207461: sparc64, and possibly other architectures, pads the length of the section holding the config file to sh_addralign bytes using NULs. This bogusly triggers an assert. Break out of the loop when we hit a NUL within that many bytes of the end. Modified: stable/7/usr.sbin/config/main.c Directory Properties: stable/7/usr.sbin/config/ (props changed) Modified: stable/7/usr.sbin/config/main.c ============================================================================== --- stable/7/usr.sbin/config/main.c Tue May 4 04:02:43 2010 (r207594) +++ stable/7/usr.sbin/config/main.c Tue May 4 04:04:37 2010 (r207595) @@ -667,7 +667,7 @@ kernconfdump(const char *file) struct stat st; FILE *fp, *pp; int error, len, osz, r; - unsigned int i, off, size; + unsigned int i, off, size, t1, t2, align; char *cmd, *o; r = open(file, O_RDONLY); @@ -686,8 +686,8 @@ kernconfdump(const char *file) if (o == NULL) errx(EXIT_FAILURE, "Couldn't allocate memory"); /* ELF note section header. */ - asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 5 kern_conf" - "| tail -2 | cut -d ' ' -f 2 | paste - - -", file); + asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 8 kern_conf" + "| tail -5 | cut -d ' ' -f 2 | paste - - - - -", file); if (cmd == NULL) errx(EXIT_FAILURE, "asprintf() failed"); pp = popen(cmd, "r"); @@ -696,24 +696,28 @@ kernconfdump(const char *file) free(cmd); len = fread(o, osz, 1, pp); pclose(pp); - r = sscanf(o, "%d\t%d", &off, &size); + r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align); free(o); - if (r != 2) + if (r != 5) errx(EXIT_FAILURE, "File %s doesn't contain configuration " "file. Either unsupported, or not compiled with " "INCLUDE_CONFIG_FILE", file); r = fseek(fp, off, SEEK_CUR); if (r != 0) errx(EXIT_FAILURE, "fseek() failed"); - for (i = 0; i < size - 1; i++) { + for (i = 0; i < size; i++) { r = fgetc(fp); if (r == EOF) break; /* * If '\0' is present in the middle of the configuration * string, this means something very weird is happening. - * Make such case very visible. + * Make such case very visible. However, some architectures + * pad the length of the section with NULs to a multiple of + * sh_addralign, allow a NUL in that part of the section. */ + if (r == '\0' && (size - i) < align) + break; assert(r != '\0' && ("Char present in the configuration " "string mustn't be equal to 0")); fputc(r, stdout);