From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id E0AB93858D33 for ; Tue, 24 Jan 2023 14:35:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0AB93858D33 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-x52a.google.com with SMTP id w11so3202549edv.0 for ; Tue, 24 Jan 2023 06:35:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IeRd9EgM6F7ns09ADMVT6GuZArekDx5I/yQG1rRIPX0=; b=QVhbgEUaZ+uumAvd/YAXdNn7+bFm671drPmxOzxKoctW3L+GlXG63Jb2An2/lYf/pE ADhjk1fqAiy5BytjvIaVzFWe75B1k4nCKqHPKlGWiJlrzHZ0jqmm37WVjonnd9d+q5No T1PX9w3KJL+fq4CfEjHkt6L7evV42uDE1vwCnA15rur9/eL6AAwysbrFTbP+evI1TEM0 viUeM1D4TdhBeFc6rKIK51m5xiM6V96S/O3sof2+OR0y5jeA2jsWfzHXA9rpJ5Koc3iA bQ3LJZBVI2o+dwU/6rPu8sw4BJVKGpJdSmMQ/cvXAV1AGWVeethAvRKpglBy38rsRmU7 M0LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IeRd9EgM6F7ns09ADMVT6GuZArekDx5I/yQG1rRIPX0=; b=PMcZ4zPXF9O87sKNaTSgFJg7d1PHiG9Fo7Bz4A8G+fUbdCPJhI+VtBbneiApOEU3Xk Bh2c/ksTPmqHmZZBH75ngjQC/+TnQLJX5PHzLAc7Zdouuf2AUZ0IPal5C7OMRxQumG0k JVAm03DtfItP64PwrIclVwxLuat5oPazFkzNsRl2/OhrWi7gVugJxb81iucOyOUqqv63 haDBIAOcqua7iA3b00udWBo0z0q51fRWOFYgbWOndStv5A7ACRhSKPTZtEy321FXAnaR GXyXd34KdUBEg/LSTtI01TYuagcWQFmTZAmvOLTPoQU2Tnev996b4872StvPpYVW15+X Z0YQ== X-Gm-Message-State: AFqh2kqoxiMbLDdsLjJZAcUzwhfAN+MMKeB1+zZ1CY6LzleqzQed8yyI drlgF6drvH/ZFxvDhpn2Bdo1BJAnCelWn227TuDGFg== X-Google-Smtp-Source: AMrXdXuZ2ybg7E4b9/LPJ7p7zS2YVpsxaH07NAqCepXoeu2qHbvBFhuABjw3hlC3+k/29W5vYVwOhiyTmaD28n1PSkE= X-Received: by 2002:a05:6402:18d:b0:48e:c98a:579d with SMTP id r13-20020a056402018d00b0048ec98a579dmr3391622edv.147.1674570933157; Tue, 24 Jan 2023 06:35:33 -0800 (PST) MIME-Version: 1.0 References: <20230120105409.54949-1-gcc@hazardy.de> <20230120105409.54949-2-gcc@hazardy.de> <83tu0ggjro.fsf@gnu.org> In-Reply-To: <83tu0ggjro.fsf@gnu.org> From: Ian Lance Taylor Date: Tue, 24 Jan 2023 06:35:21 -0800 Message-ID: Subject: Re: [PATCH 2/4] libbacktrace: detect executable path on windows To: Eli Zaretskii Cc: gcc@hazardy.de, gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,USER_IN_DEF_SPF_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Jan 24, 2023 at 5:11 AM Eli Zaretskii via Gcc-patches wrote: > > > Date: Mon, 23 Jan 2023 15:00:56 -0800 > > Cc: gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org > > From: Ian Lance Taylor via Gcc > > > > > +#ifdef HAVE_WINDOWS_H > > > + > > > +static char * > > > +windows_get_executable_path (char *buf, backtrace_error_callback error_callback, > > > + void *data) > > > +{ > > > + if (GetModuleFileNameA (NULL, buf, MAX_PATH - 1) == 0) > > > + { > > > + error_callback (data, > > > + "could not get the filename of the current executable", > > > + (int) GetLastError ()); > > > + return NULL; > > > + } > > > + return buf; > > > +} > > > > Thanks, but this seems incomplete. The docs for GetModuleFileNameA > > say that if the pathname is too long to fit into the buffer it returns > > the size of the buffer and sets the error to > > ERROR_INSUFFICIENT_BUFFER. It seems to me that in that case we should > > allocate a larger buffer and try again. > > This is correct in general, but not in this particular case. > > > On Windows it seems that MAX_PATH is not > > a true limit, as an extended length path may be up to 32767 bytes. > > The limit of 32767 characters (not bytes, AFAIK) is only applicable > when using the Unicode (a.k.a. "wide") versions of the Windows Win32 > APIs, see > > https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation > > Since the above code uses GetModuleFileNameA, which is an "ANSI" > single-byte API, it is still subject to the MAX_PATH limitation, and > MAX_PATH is defined as 260 on Windows headers. Thanks. Should this code be using GetModuleFileNameW? Or would that mean that the later call to open will fail? 260 bytes does not seem like very much for a path name these days. Ian