~ubuntu-branches/ubuntu/lucid/curl/lucid-security

« back to all changes in this revision

Viewing changes to tests/server/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-12 15:04:52 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20051212150452-2ymlra67b2p7kjyy
Tags: 7.15.1-1ubuntu1
Resynchronise with Debian to get URL parser overflow fix from 7.15.1
(CVE-2005-4077).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: util.c,v 1.3 2005/05/01 12:56:09 bagder Exp $
 
21
 * $Id: util.c,v 1.6 2005/09/15 20:22:43 bagder Exp $
22
22
 ***************************************************************************/
23
23
#include "setup.h" /* portability help from the lib directory */
24
24
 
81
81
  struct tm *now =
82
82
    localtime(&tv.tv_sec); /* not multithread safe but we don't care */
83
83
 
84
 
  char timebuf[12];
85
 
  snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%02ld",
86
 
           now->tm_hour, now->tm_min, now->tm_sec,
87
 
           tv.tv_usec/10000);
 
84
  char timebuf[20];
 
85
  snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
 
86
           now->tm_hour, now->tm_min, now->tm_sec, tv.tv_usec);
88
87
 
89
88
  va_start(ap, msg);
90
89
  vsprintf(buffer, msg, ap);
91
90
  va_end(ap);
92
91
 
93
92
  logfp = fopen(serverlogfile, "a");
94
 
  fprintf(logfp?logfp:stderr, /* write to stderr if the logfile doesn't open */
95
 
          "%s %s\n", timebuf, buffer);
96
 
  if(logfp)
 
93
  if(logfp) {
 
94
    fprintf(logfp, "%s %s\n", timebuf, buffer);
97
95
    fclose(logfp);
98
 
}
 
96
  }
 
97
}
 
98
 
 
99
#if defined(WIN32) && !defined(__CYGWIN__)
 
100
/* use instead of perror() on generic windows */
 
101
void win32_perror (const char *msg)
 
102
{
 
103
  char buf[256];
 
104
  DWORD err = WSAGetLastError();
 
105
 
 
106
  if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
 
107
                     LANG_NEUTRAL, buf, sizeof(buf), NULL))
 
108
     snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
 
109
  if (msg)
 
110
     fprintf(stderr, "%s: ", msg);
 
111
  fprintf(stderr, "%s\n", buf);
 
112
}
 
113
#endif
 
114
 
 
115
#if defined(WIN32) && !defined(__CYGWIN__)
 
116
void win32_init(void)
 
117
{
 
118
  WORD wVersionRequested;
 
119
  WSADATA wsaData;
 
120
  int err;
 
121
  wVersionRequested = MAKEWORD(2, 0);
 
122
 
 
123
  err = WSAStartup(wVersionRequested, &wsaData);
 
124
 
 
125
  if (err != 0) {
 
126
    perror("Winsock init failed");
 
127
    logmsg("Error initialising winsock -- aborting\n");
 
128
    exit(1);
 
129
  }
 
130
 
 
131
  if ( LOBYTE( wsaData.wVersion ) != 2 ||
 
132
       HIBYTE( wsaData.wVersion ) != 0 ) {
 
133
 
 
134
    WSACleanup();
 
135
    perror("Winsock init failed");
 
136
    logmsg("No suitable winsock.dll found -- aborting\n");
 
137
    exit(1);
 
138
  }
 
139
}
 
140
 
 
141
void win32_cleanup(void)
 
142
{
 
143
  WSACleanup();
 
144
}
 
145
#endif
 
146
 
 
147
/* set by the main code to point to where the test dir is */
 
148
const char *path=".";
 
149
 
 
150
char *test2file(long testno)
 
151
{
 
152
  static char filename[256];
 
153
  snprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno);
 
154
  return filename;
 
155
}
 
156