From owner-svn-src-head@FreeBSD.ORG Fri Jun 19 22:24:59 2015 Return-Path: Delivered-To: svn-src-head@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B251A9D2; Fri, 19 Jun 2015 22:24:59 +0000 (UTC) (envelope-from sobomax@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A0494156; Fri, 19 Jun 2015 22:24:59 +0000 (UTC) (envelope-from sobomax@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5JMOxMS097307; Fri, 19 Jun 2015 22:24:59 GMT (envelope-from sobomax@FreeBSD.org) Received: (from sobomax@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5JMOxpC097306; Fri, 19 Jun 2015 22:24:59 GMT (envelope-from sobomax@FreeBSD.org) Message-Id: <201506192224.t5JMOxpC097306@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: sobomax set sender to sobomax@FreeBSD.org using -f From: Maxim Sobolev Date: Fri, 19 Jun 2015 22:24:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284614 - head/sys/boot/uboot/lib X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jun 2015 22:24:59 -0000 Author: sobomax Date: Fri Jun 19 22:24:58 2015 New Revision: 284614 URL: https://svnweb.freebsd.org/changeset/base/284614 Log: Provide bug4bug workaround for certain dumbiness of the u-boot's API_env_enum function, which is expected to set returned env to NULL upon reaching the end of the environment list but fails to do so in certain cases. The respective u-boot code looks like the following (HEAD at the time of this commit): --- api.c --- 496 static int API_env_enum(va_list ap) ... 510 *next = last; 511 512 for (i = 0; env_get_char(i) != '\0'; i = n + 1) { 513 for (n = i; env_get_char(n) != '\0'; ++n) { 514 if (n >= CONFIG_ENV_SIZE) { 515 /* XXX shouldn't we set *next = NULL?? */ 516 return 0; 517 } 518 } ------------- The net result is that any unfortunate user of the loader's ub_env_enum() function hitting this condition would be trapped in the infinite loop, as the main use pattern of ub_env_enum() is basically the following: while ((env = ub_env_enum(env)) != NULL) { DO STUFF } Which would stuck forever with the last element. Modified: head/sys/boot/uboot/lib/glue.c Modified: head/sys/boot/uboot/lib/glue.c ============================================================================== --- head/sys/boot/uboot/lib/glue.c Fri Jun 19 21:55:12 2015 (r284613) +++ head/sys/boot/uboot/lib/glue.c Fri Jun 19 22:24:58 2015 (r284614) @@ -513,7 +513,7 @@ ub_env_enum(const char *last) if (!syscall(API_ENV_ENUM, NULL, (uint32_t)last, (uint32_t)&env)) return (NULL); - if (env == NULL) + if (env == NULL || last == env) /* no more env. variables to enumerate */ return (NULL);