From patchwork Tue Sep 19 07:32:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 141716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3195468vqi; Tue, 19 Sep 2023 00:33:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCpD+kvlYW45xvrnD/KrZag7ZKRx9ah3gh5mLSp8jbHWeGETPjMAwZHYUdTZOkJgbXAN/v X-Received: by 2002:a05:6402:64e:b0:523:2274:91cb with SMTP id u14-20020a056402064e00b00523227491cbmr8861770edx.12.1695108795473; Tue, 19 Sep 2023 00:33:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695108795; cv=none; d=google.com; s=arc-20160816; b=Y01VhZmgVR/R+HexKKn41eW2M+Y8HYEfVhbAd/tceVYV4rmvMI3E/SCY0F1lluFJAi xUx+mLBlh2F25udl0rRI+8ppsdLec/pSnTPooSC4zZE18SURXJ5Dri+UDaplbQ8dSqAf KkFU9H2/+PCVXu7YQwHPwcfWxiT12Xt9Hc2Tyb+s8t0xqloODXkzrwZVmUzoq6wB+G3+ iYm/FECX2ufsstnB2sYlllmohZbBzHgRQIxSxobM/t8RHM/LeCRV9bHT7Q0564sxPRNR iFNHEiR8E7rxuB8mfmshnnLiN440L0B/AFmRS2uOow9mziLgOWe1Mu6rsj8XoLmvDFev abbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=mtoeW7llSL0GU115Fi7kzQJzRr12x0xqKT44/HK6TOI=; fh=zj78/O+q0guS5uROWuq0Sap/gJBgRHz16re1BmqZyHM=; b=csuAhmO14iQHCQ83AN4BFZ7H+xig71M4S1Ag34GSo3K8I+h06SrSJ/c/NHiWY6VBam BmoIIGIAW7U4xCGsPKmqRCPb1B6vW3vxBIhe5yPS72m59o9S1IdSMWSsGsmYpviqgmLY aDhQgxz5b8hUyqEF9uBBl7k8FZMZANClS2MRPRRErx1V60hsiffu4UzoWB9TrJ/YINVm SaWtulRCdTBBym3QQ50jumweSSs5kH/54Ez/cA4Bo21HedF2GGeKkCxdE/DG5DSS0EjQ xhMTNnlw8ciuGmTuDZfakJKbi+myYKvA1LSme8oa11Eo88IKHKNQ6NEZn5LLFxqYNUoO luQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GzAmIQwR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k2-20020aa7c382000000b0053114796a9dsi3267946edq.155.2023.09.19.00.33.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 00:33:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GzAmIQwR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27B21385772B for ; Tue, 19 Sep 2023 07:33:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27B21385772B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695108794; bh=mtoeW7llSL0GU115Fi7kzQJzRr12x0xqKT44/HK6TOI=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GzAmIQwRbJ5MQg6QA87kZgzO6z/5swayjjD+fGY9Pb4KVkLswNA0Nxja8gjABSXPq x7ANTVXmtvSOYuC5XDbEDyAmcNSnQ5agmiplNZKP9fTHWQcD1FXuTiIFScSwkQ8DyN V8RVzOAdjl1g6yvvuGyAeUy+F8eeXw+ObmK2H4Zg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 208D03858C2B for ; Tue, 19 Sep 2023 07:32:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 208D03858C2B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-259-2iZEQbSzP9-HlaDmD5iOKg-1; Tue, 19 Sep 2023 03:32:24 -0400 X-MC-Unique: 2iZEQbSzP9-HlaDmD5iOKg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35D65185A790; Tue, 19 Sep 2023 07:32:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.82]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D687920268CC; Tue, 19 Sep 2023 07:32:23 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 38J7WMZI2523786 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 19 Sep 2023 09:32:22 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38J7WM112523785; Tue, 19 Sep 2023 09:32:22 +0200 Date: Tue, 19 Sep 2023 09:32:21 +0200 To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] libgomp: Handle NULL environ like pointer to NULL pointer [PR111413] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777450400354657047 X-GMAIL-MSGID: 1777450400354657047 Hi! clearenv function just sets environ to NULL (after sometimes freeing it), rather than setting it to a pointer to NULL, and our code was assuming it is always non-NULL. Fixed thusly, the change seems to be large but actually is just + if (environ) for (env = environ; *env != 0; env++) plus reindentation. I've also noticed the block after this for loop was badly indented (too much) and fixed that too. No testcase added, as it needs clearenv + dlopen. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-09-19 Jakub Jelinek PR libgomp/111413 * env.c (initialize_env): Don't dereference environ if it is NULL. Reindent. Jakub --- libgomp/env.c.jj 2023-06-20 08:57:39.095494805 +0200 +++ libgomp/env.c 2023-09-18 10:53:21.976636936 +0200 @@ -2224,139 +2224,140 @@ initialize_env (void) none = gomp_get_initial_icv_item (GOMP_DEVICE_NUM_FOR_NO_SUFFIX); initialize_icvs (&none->icvs); - for (env = environ; *env != 0; env++) - { - if (!startswith (*env, "OMP_")) - continue; - - /* Name of the environment variable without suffix "OMP_". */ - char *name = *env + sizeof ("OMP_") - 1; - for (omp_var = 0; omp_var < OMP_VAR_CNT; omp_var++) - { - if (startswith (name, envvars[omp_var].name)) - { - pos = envvars[omp_var].name_len; - if (name[pos] == '=') - { - pos++; - flag_var_addr - = add_initial_icv_to_list (GOMP_DEVICE_NUM_FOR_NO_SUFFIX, - envvars[omp_var].flag_vars[0], - params); - } - else if (startswith (&name[pos], "_DEV=") - && envvars[omp_var].flag & GOMP_ENV_SUFFIX_DEV) - { - pos += 5; - flag_var_addr - = add_initial_icv_to_list (GOMP_DEVICE_NUM_FOR_DEV, - envvars[omp_var].flag_vars[0], - params); - } - else if (startswith (&name[pos], "_ALL=") - && envvars[omp_var].flag & GOMP_ENV_SUFFIX_ALL) - { - pos += 5; - flag_var_addr - = add_initial_icv_to_list (GOMP_DEVICE_NUM_FOR_ALL, - envvars[omp_var].flag_vars[0], - params); - } - else if (startswith (&name[pos], "_DEV_") - && envvars[omp_var].flag & GOMP_ENV_SUFFIX_DEV_X) - { - pos += 5; - if (!get_device_num (*env, &name[pos], &dev_num, - &dev_num_len)) - break; + if (environ) + for (env = environ; *env != 0; env++) + { + if (!startswith (*env, "OMP_")) + continue; - pos += dev_num_len + 1; - flag_var_addr - = add_initial_icv_to_list (dev_num, - envvars[omp_var].flag_vars[0], - params); - } - else - { - gomp_error ("Invalid environment variable in %s", *env); - break; - } - env_val = &name[pos]; - - if (envvars[omp_var].parse_func (*env, env_val, params)) - { - for (i = 0; i < 3; ++i) - if (envvars[omp_var].flag_vars[i]) - gomp_set_icv_flag (flag_var_addr, - envvars[omp_var].flag_vars[i]); - else + /* Name of the environment variable without suffix "OMP_". */ + char *name = *env + sizeof ("OMP_") - 1; + for (omp_var = 0; omp_var < OMP_VAR_CNT; omp_var++) + { + if (startswith (name, envvars[omp_var].name)) + { + pos = envvars[omp_var].name_len; + if (name[pos] == '=') + { + pos++; + flag_var_addr + = add_initial_icv_to_list (GOMP_DEVICE_NUM_FOR_NO_SUFFIX, + envvars[omp_var].flag_vars[0], + params); + } + else if (startswith (&name[pos], "_DEV=") + && envvars[omp_var].flag & GOMP_ENV_SUFFIX_DEV) + { + pos += 5; + flag_var_addr + = add_initial_icv_to_list (GOMP_DEVICE_NUM_FOR_DEV, + envvars[omp_var].flag_vars[0], + params); + } + else if (startswith (&name[pos], "_ALL=") + && envvars[omp_var].flag & GOMP_ENV_SUFFIX_ALL) + { + pos += 5; + flag_var_addr + = add_initial_icv_to_list (GOMP_DEVICE_NUM_FOR_ALL, + envvars[omp_var].flag_vars[0], + params); + } + else if (startswith (&name[pos], "_DEV_") + && envvars[omp_var].flag & GOMP_ENV_SUFFIX_DEV_X) + { + pos += 5; + if (!get_device_num (*env, &name[pos], &dev_num, + &dev_num_len)) break; - } - break; - } - } - } + pos += dev_num_len + 1; + flag_var_addr + = add_initial_icv_to_list (dev_num, + envvars[omp_var].flag_vars[0], + params); + } + else + { + gomp_error ("Invalid environment variable in %s", *env); + break; + } + env_val = &name[pos]; - all = gomp_get_initial_icv_item (GOMP_DEVICE_NUM_FOR_ALL); - for (omp_var = 0; omp_var < OMP_HOST_VAR_CNT; omp_var++) - { - if (none != NULL - && gomp_get_icv_flag (none->flags, host_envvars[omp_var].flag_var)) - get_icv_member_addr (&none->icvs, - host_envvars[omp_var].flag_var, params); - else if (all != NULL - && gomp_get_icv_flag (all->flags, - host_envvars[omp_var].flag_var)) - get_icv_member_addr (&all->icvs, host_envvars[omp_var].flag_var, - params); - else - continue; + if (envvars[omp_var].parse_func (*env, env_val, params)) + { + for (i = 0; i < 3; ++i) + if (envvars[omp_var].flag_vars[i]) + gomp_set_icv_flag (flag_var_addr, + envvars[omp_var].flag_vars[i]); + else + break; + } - switch (host_envvars[omp_var].type_code) - { - case PARSE_INT: - for (i = 0; i < 3; ++i) - if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) - *(int *) (host_envvars[omp_var].dest[i]) = *(int *) params[i]; - break; - case PARSE_BOOL: - for (i = 0; i < 3; ++i) - if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) - *(bool *) (host_envvars[omp_var].dest[i]) = *(bool *) params[i]; - break; - case PARSE_UINT: - for (i = 0; i < 3; ++i) - if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) - *(unsigned int *) (host_envvars[omp_var].dest[i]) - = *(unsigned int *) params[i]; - break; - case PARSE_ULONG: - for (i = 0; i < 3; ++i) - if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) - *(unsigned long *) (host_envvars[omp_var].dest[i]) - = *(unsigned long *) params[i]; - break; - case PARSE_UCHAR: - for (i = 0; i < 3; ++i) - if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) - *(unsigned char *) (host_envvars[omp_var].dest[i]) - = *(unsigned char *) params[i]; - break; - case PARSE_SCHEDULE: - *(enum gomp_schedule_type *) (host_envvars[omp_var].dest[0]) - = *(enum gomp_schedule_type *) params[0]; - *(int *) (host_envvars[omp_var].dest[1]) = *(int *) params[1]; - break; - case PARSE_BIND: - *(char *) (host_envvars[omp_var].dest[0]) = *(char *) params[0]; - *(char **) (host_envvars[omp_var].dest[1]) = *(char **) params[1]; - *(unsigned long *) (host_envvars[omp_var].dest[2]) - = *(unsigned long *) params[2]; - break; + break; + } } } + all = gomp_get_initial_icv_item (GOMP_DEVICE_NUM_FOR_ALL); + for (omp_var = 0; omp_var < OMP_HOST_VAR_CNT; omp_var++) + { + if (none != NULL + && gomp_get_icv_flag (none->flags, host_envvars[omp_var].flag_var)) + get_icv_member_addr (&none->icvs, + host_envvars[omp_var].flag_var, params); + else if (all != NULL + && gomp_get_icv_flag (all->flags, + host_envvars[omp_var].flag_var)) + get_icv_member_addr (&all->icvs, host_envvars[omp_var].flag_var, + params); + else + continue; + + switch (host_envvars[omp_var].type_code) + { + case PARSE_INT: + for (i = 0; i < 3; ++i) + if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) + *(int *) (host_envvars[omp_var].dest[i]) = *(int *) params[i]; + break; + case PARSE_BOOL: + for (i = 0; i < 3; ++i) + if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) + *(bool *) (host_envvars[omp_var].dest[i]) = *(bool *) params[i]; + break; + case PARSE_UINT: + for (i = 0; i < 3; ++i) + if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) + *(unsigned int *) (host_envvars[omp_var].dest[i]) + = *(unsigned int *) params[i]; + break; + case PARSE_ULONG: + for (i = 0; i < 3; ++i) + if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) + *(unsigned long *) (host_envvars[omp_var].dest[i]) + = *(unsigned long *) params[i]; + break; + case PARSE_UCHAR: + for (i = 0; i < 3; ++i) + if (host_envvars[omp_var].dest[i] != NULL && params[i] != NULL) + *(unsigned char *) (host_envvars[omp_var].dest[i]) + = *(unsigned char *) params[i]; + break; + case PARSE_SCHEDULE: + *(enum gomp_schedule_type *) (host_envvars[omp_var].dest[0]) + = *(enum gomp_schedule_type *) params[0]; + *(int *) (host_envvars[omp_var].dest[1]) = *(int *) params[1]; + break; + case PARSE_BIND: + *(char *) (host_envvars[omp_var].dest[0]) = *(char *) params[0]; + *(char **) (host_envvars[omp_var].dest[1]) = *(char **) params[1]; + *(unsigned long *) (host_envvars[omp_var].dest[2]) + = *(unsigned long *) params[2]; + break; + } + } + if (((none != NULL && gomp_get_icv_flag (none->flags, GOMP_ICV_BIND)) || (all != NULL && gomp_get_icv_flag (all->flags, GOMP_ICV_BIND))) && gomp_global_icv.bind_var == omp_proc_bind_false)