Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 9429a65a904761c361968ef9c50793bc14326b534035bd5c94c088bb27adbf1d
Ticket: 85fc8bca030ecf2656929cc0a222145a57cca8b2
Pointer arithmetic with NULL in buildInfoObjCmd()
User & Date: chrstphrchvz on 2025-08-31 22:50:10
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    Example UBSan error for the default case:
    <pre>
    % tcl::build-info boneless
    <b>tclBasic.c:755:36: <span style="color:firebrick">runtime error:</span> applying non-zero offset 1 to null pointer</b>
    0
    </pre>
    
    
    The error is due to <tt>p++</tt> being used as the for loop condition. I believe there is an instance of this in the <tt>ID_COMPILER</tt> case as well. One possible fix:
    
    <pre>
    --- generic/tclBasic.c
    +++ generic/tclBasic.c
    @@ -731,7 +731,8 @@
     	}
     	return TCL_OK;
         case ID_COMPILER:
    <span style="color:firebrick">-	for (p = strchr(buildData, '.'); p++; p = strchr(p, '.')) {</span>
    <span style="color:green">+	for (p = strchr(buildData, '.'); p != NULL; p = strchr(p, '.')) {
    +	    p++;</span>
     	    /*
     	     * Does the word begin with one of the standard prefixes?
     	     */
    @@ -752,7 +753,8 @@
     	break;
         default:		/* Boolean test for other identifiers' presence */
     	arg = TclGetStringFromObj(objv&#91;1&#93;, &len);
    <span style="color:firebrick">-	for (p = strchr(buildData, '.'); p++; p = strchr(p, '.')) {</span>
    <span style="color:green">+	for (p = strchr(buildData, '.'); p != NULL; p = strchr(p, '.')) {
    +	    p++;</span>
     	    if (!strncmp(p, arg, len)
     		    &amp;&amp; ((p&#91;len&#93; == '.') || (p&#91;len&#93; == '-') || (p&#91;len&#93; == '\0'))) {
     		if (p&#91;len&#93; == '-') {
    </pre>
    
  5. foundin changed to: "core-8-branch"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "chrstphrchvz"
  14. subsystem changed to: "54. Configuration Reporting"
  15. title changed to: "Pointer arithmetic with NULL in buildInfoObjCmd()"
  16. type changed to: "Bug"