delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/14/10:53:32

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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
Date: Tue, 14 May 2002 10:44:20 -0400 (EDT)
From: Mark Blackburn <marklist AT fangorn DOT ca>
To: cygwin AT cygwin DOT com
Subject: Possible error in cygpath
Message-ID: <Pine.LNX.3.96.1020514103637.9209A-100000@rivendell.fangorn.ca>
MIME-Version: 1.0

In cygpath.cc there is a function that goes like this:

static char *
get_short_name (const char *filename)
{
  char *sbuf;
  DWORD len = GetShortPathName (filename, NULL, 0);
  if (len == ERROR_INVALID_PARAMETER)
    {
      fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
	       filename);
      exit (2);
    }
  sbuf = (char *) malloc (++len);
  if (sbuf == NULL)
    {
      fprintf (stderr, "%s: out of memory\n", prog_name);
      exit (1);
    }
  if (GetShortPathName (filename, sbuf, len) == ERROR_INVALID_PARAMETER)
    {
      fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
	       filename);
      exit (2);
    }
  fprintf(stderr, "get_short_name: sbuf=%s\n",sbuf);
  return sbuf;
}


The spot where it says:
  DWORD len = GetShortPathName (filename, NULL, 0);
  if (len == ERROR_INVALID_PARAMETER)

is what worries me, I think it should be a little more like:
  DWORD len = GetShortPathName (filename, NULL, 0);
  if (len == 0 && GetLastError() == ERROR_INVALID_PARAMETER)

I don't know how this problem might manifest itself though I suspect that
if GetShortPathName returns a length of 87 then bad things might happen 
( 87 The parameter is incorrect. ERROR_INVALID_PARAMETER).

By the way I noticed this while I was trying to add a -l option to cygpath
which is similar to the -s option but it will convert a muddled 8.3 name
like PROGRA~1 to "Program Files" and I want to know if anyone else might
have been working on that.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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