From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 74C87388A43B for ; Fri, 9 Apr 2021 16:53:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 74C87388A43B Received: by mail-io1-xd2f.google.com with SMTP id z136so6558318iof.10 for ; Fri, 09 Apr 2021 09:53:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=SvAJIjXoR1w5M01WAOJRVt8RlMlPcKcrO9jpQQgtVHE=; b=lmkhfTfO768kg2awGCC3mbcuNSnxg4zoz81pTudHu5rp2pws7Rjb6t68e9XHdZJrHz bUreD0qLKruv8+OIg3XQiJeOMScxy3lOk/WFw7ya9AR70BTOP7o3vv3Zm7h1LHFvqnKT 2chYhfbREIqUPfM2aKAMYcK+cyGJvpMCLq35fJPJHRm+QriuFYVH13LLsfmRZbJXBA+5 l8IO1LbUjFG2OPcAptm+hRxTOgw93YmrNz00HZiO5KiynvuJVDsVV5IXxsngfDhuztai LJoMPWW0uWszzpfLLvgCLvaUaakyxtD4JtMzNZS44hxf/68AT/Z8hYIc+jofMdldeB7V c8sw== X-Gm-Message-State: AOAM530RFfoUxUo4Vcwc4HTmR2xnFWk8O3RxoXhjVNenALDkKfhFtZWP Nl+7FQv5ngk2EccNfbvu/8BYBWfgLeTb4wchSeISHDNN23I= X-Google-Smtp-Source: ABdhPJzcbwy+NPRjRlsJKg6nvku4WLxlztI9mfhl133VjFhObk+szxHIUoKmzDP4GhO/GLxbzvVEdpVYa/FqMCykaj8= X-Received: by 2002:a6b:6f14:: with SMTP id k20mr12389280ioc.52.1617987219732; Fri, 09 Apr 2021 09:53:39 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6602:349:0:0:0:0 with HTTP; Fri, 9 Apr 2021 09:53:39 -0700 (PDT) From: Peng Yu Date: Fri, 9 Apr 2021 11:53:39 -0500 Message-ID: Subject: When is it OK to pass NULLs to the 2nd and 3rd args of execve()? To: libc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2021 16:53:41 -0000 Hi, I am wondering when (all possible legitimate cases) it is OK to pass NULLs to execve's 2nd and 3rd args. #include #include int main(int argc, char *argv[]) { if(execve(argv[1], NULL, NULL) == -1) { perror("execvp()"); return 1; } return 0; } I tried the above program. It works when it is called with `/bin/sh`. My guess is that when the program being exec'ed don't use its args and envs, then then 2nd and 3rd args of execve() can be NULLs. Could anybody correct me if I am wrong? -- Regards, Peng