public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Abhijit Bhattacharjee <itabhijitb@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Bash silently truncates the Command Line when called programatically via CreateProcess as MAXPATHLEN was reduced to 8192 from 16384
Date: Tue, 27 May 2014 22:11:00 -0000	[thread overview]
Message-ID: <CANMjiJqkm1pD5zuKWc_aRw8h9mzfdpwSkk6u6ybLmgHKGEd0PQ@mail.gmail.com> (raw)
In-Reply-To: <CANMjiJpDU-aVxg1X8G_Lk8pKLEmXbs24+ieD=w3f8ZmQ2jdjTw@mail.gmail.com>

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

  parent reply	other threads:[~2014-05-27 13:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26 17:28 Abhijit Bhattacharjee
2014-05-26 20:38 ` Christopher Faylor
2014-05-27  3:18   ` René Berber
2014-05-27  6:54     ` Christopher Faylor
     [not found]       ` <CANMjiJpDU-aVxg1X8G_Lk8pKLEmXbs24+ieD=w3f8ZmQ2jdjTw@mail.gmail.com>
2014-05-27 22:11         ` Abhijit Bhattacharjee [this message]
2014-05-28  9:48           ` Christopher Faylor
2014-05-28 11:04           ` David Stacey
2014-05-28 19:48             ` Warren Young
2014-05-31 13:37               ` Abhijit Bhattacharjee
2014-05-31 17:55                 ` Cliff Hones
2014-05-31 19:22                 ` Christopher Faylor
2014-05-28 16:07 Houder
2014-05-28 17:59 ` Christopher Faylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANMjiJqkm1pD5zuKWc_aRw8h9mzfdpwSkk6u6ybLmgHKGEd0PQ@mail.gmail.com \
    --to=itabhijitb@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).