delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/05/27/09:20:46

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:from:date
:message-id:subject:to:content-type; q=dns; s=default; b=wPlkd0S
FDVN3w8Y3AvZgvQo4wCtgLcrCX7NczFEWdjWGAFfr0jKFDceQcO13igTlVsQNGo8
173UDNejfucvlTac9kVp6pTtS10vMmVVKRMoV+t1qB8vAa1cAK+DZcAljg8ScmIW
bbZoJD6o//lmLM2Cg4AjRwcy3Y+KJSisHwa4=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:from:date
:message-id:subject:to:content-type; s=default; bh=Gw/vxmS5vZtaA
SLDxHzuj4Kzg2w=; b=ZK8rlnQVqaaseKj81/EVb9/crEethsDkwkcnJ7tcDLH3L
2GTbqMrhLoS6+eOai+/0Kof6WsofP6aT4EVnkS4pQpPaQXtz0eHBOFOHFQxEEPVN
GAdkCLomqZ96Vx1sfOgxCIGGmb0/a2zmRfSF3gDDL8gQg0ldf5r+hf5P9wkDhc=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-oa0-f43.google.com
X-Received: by 10.60.70.200 with SMTP id o8mr27300377oeu.55.1401196823419; Tue, 27 May 2014 06:20:23 -0700 (PDT)
MIME-Version: 1.0
In-Reply-To: <CANMjiJpDU-aVxg1X8G_Lk8pKLEmXbs24+ieD=w3f8ZmQ2jdjTw@mail.gmail.com>
References: <CANMjiJqz6uJ7pp=iS5FK_ZnS9nxCT1fY+EndcgzPan7sv2pXJA AT mail DOT gmail DOT com> <20140526200857 DOT GA3903 AT ednor DOT casa DOT cgf DOT cx> <lm08n5$tgp$1 AT ger DOT gmane DOT org> <20140526212219 DOT GA4754 AT ednor DOT casa DOT cgf DOT cx> <CANMjiJpDU-aVxg1X8G_Lk8pKLEmXbs24+ieD=w3f8ZmQ2jdjTw AT mail DOT gmail DOT com>
From: Abhijit Bhattacharjee <itabhijitb AT gmail DOT com>
Date: Tue, 27 May 2014 18:49:43 +0530
Message-ID: <CANMjiJqkm1pD5zuKWc_aRw8h9mzfdpwSkk6u6ybLmgHKGEd0PQ@mail.gmail.com>
Subject: Re: Bash silently truncates the Command Line when called programatically via CreateProcess as MAXPATHLEN was reduced to 8192 from 16384
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

Yes, MSVS is Microsoft Visual Studio.

and I am using the make for Windows
(http://gnuwin32.sourceforge.net/packages/make.htm).

Please note, when I am saying the path is getting truncated, its the
bash that is truncating it. Also, its immaterial how and what is
getting called. With the latest Cygwin, any program that is compiled
and linked with the CRT would exhibit this behavior. The truncation
issue in the CRT is best demonstrated by the following Code couplets

Caller.cpp
--------------
#include <iostream>
#include <windows.h>
#include <string.h>
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
int main(int argc, char *argv[]) {
    if (argc <= 1) return -1;
    char arg[10000] = {0};
    strncpy(arg, argv[argc-1], _countof(arg));
    strncat(arg," ", _countof(arg));
    memset(arg + strlen(arg), 'X', _countof(arg) - strlen(arg) - 2);
    strncat(arg, "\"", _countof(arg));
    STARTUPINFO startInfo;
    PROCESS_INFORMATION procInfo;
    memset( &startInfo, 0, sizeof(startInfo) );
    memset( &procInfo, 0, sizeof(procInfo) );
    if (CreateProcess(NULL,
        arg,
        NULL,
        0,
        TRUE,
        0,
        NULL,
        NULL,
        &startInfo,
        &procInfo) == FALSE) {
            std::cout<<"Error Code "<<GetLastError()<<std::endl;
    } else {
        WaitForSingleObject(procInfo.hProcess, INFINITE );
        CloseHandle( procInfo.hProcess );
        CloseHandle( procInfo.hThread );
        std::cout<<"Send Length "<<strlen(arg)<<std::endl;
    }
    return 0;
};

Callee.cpp
-------------

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <windows.h>
int main (int argc, char **argv) {
    printf("%s\n",argv[argc-1]);
    printf("%d\n",argc);
    printf("Received Length %d\n",strlen(argv[argc-1]));
    return 0;

}


Compile and Run The Programs as
-----------------------------------------

$g++ -g -o Caller.exe Caller.cpp
$g++ -g -o Callee.exe Callee.cpp
$./Caller.exe Callee.exe




Also Note, if you would like to review the code that is responsible
for the truncation, I would suggest you to refer the function

Source: winsup\cygwin\glob.cc
int glob(const char *__restrict pattern, int flags, int
(*errfunc)(const char *, int), glob_t *__restrict pglob)

and notice pathbuf is defined as

Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;

where

#undef MAXPATHLEN
#define MAXPATHLEN 8192

and to complete here is the call stack

glob(const char *__restrict pattern, int flags, int (*errfunc)(const
char *, int), glob_t *__restrict pglob)
globify (char *word, char **&argv, int &argc, int &argvlen)  - Line
265 of winsup\cygwin\dcrt0.cc
build_argv (char *cmd, char **&argv, int &argc, int winshell) - Line
353 of winsup\cygwin\dcrt0.cc
dll_crt0_1 (void *) - Line 953 of winsup\cygwin\dcrt0.cc
_dll_crt0 () - Line 1098 of winsup\cygwin\dcrt0.cc
dll_crt0 - Line 1110 of winsup\cygwin\dcrt0.cc

Rgrds,
Abhijit

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019