~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to httpget.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-09-07 15:57:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040907155757-pgypftl9bt2uqyyl
Tags: 0.59r-16
* layer2.c: Fix buffer overflow in layer2 decoder (CVE ID CAN-2004-0805).
* Makefile: Fix compiler options to build for generic targets on ARM,
  but optimise for xscale. Closes: #261255
* README.3DNOW, dct36_3dnow.s, dct64_3dnow.s, decode_3dnow.s,
  decode_i386.c, equalizer_3dnow.s, getcpuflags.s, layer3.c, mpg123.c,
  mpg123.h, tabinit.c, debian/rules: Apply patch by KIMURA Takuhiro and
  Syuuhei Kashiyama to fix errors in 3dnow-optimised decoding.
  Thanks to Alberto Garcia for the patch-merging. Closes: #242212
* debian/prerm: De-register mp3-decoder alternative. Closes: #222982
* debian/changelog: Convert to utf8.
* debian/control: Bump standards version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        }
49
49
}
50
50
 
51
 
void readstring (char *string, int maxlen, FILE *f)
 
51
int readstring (char *string, int maxlen, FILE *f)
52
52
{
53
53
#if 0
54
54
        char *result;
55
55
#endif
56
56
        int pos = 0;
57
57
 
58
 
        while(1) {
 
58
        while(pos < maxlen) {
59
59
                if( read(fileno(f),string+pos,1) == 1) {
60
60
                        pos++;
61
61
                        if(string[pos-1] == '\n') {
62
 
                                string[pos] = 0;
63
62
                                break;
64
63
                        }
65
64
                }
68
67
                        exit(1);
69
68
                }
70
69
        }
 
70
 
 
71
        string[pos] = 0;
 
72
 
 
73
        return pos;
 
74
 
71
75
#if 0
72
76
        do {
73
77
                result = fgets(string, maxlen, f);
206
210
                                        host ? host : "");
207
211
                                exit (1);
208
212
                        }
209
 
                        if (host)
 
213
                       if (host) {
210
214
                                free (host);
 
215
                               host = NULL;
 
216
                       }
211
217
                }
212
218
                else
213
219
                        proxyip = INADDR_NONE;
219
225
                fprintf (stderr, "malloc() failed, out of memory.\n");
220
226
                exit (1);
221
227
        }
222
 
        strncpy (purl, url, 1023);
223
 
        purl[1023] = '\0';
 
228
        /*
 
229
         * 2000-10-21:
 
230
         * We would like spaces to be automatically converted to %20's when
 
231
         * fetching via HTTP.
 
232
         * -- Martin Sj�gren <md9ms@mdstud.chalmers.se>
 
233
         */
 
234
        if ((sptr = strchr(url, ' ')) == NULL) {
 
235
                strncpy (purl, url, 1023);
 
236
                purl[1023] = '\0';
 
237
        }
 
238
        else {
 
239
                int purllength = 0;
 
240
                char *urlptr = url;
 
241
                purl[0] = '\0';
 
242
                do {
 
243
                        purllength += sptr-urlptr + 3;
 
244
                        if (purllength >= 1023)
 
245
                                break;
 
246
                        strncat (purl, urlptr, sptr-urlptr);
 
247
                        strcat (purl, "%20");
 
248
                        urlptr = sptr + 1;
 
249
                } while ((sptr = strchr (urlptr, ' ')) != NULL);
 
250
                strcat (purl, urlptr);
 
251
        }
224
252
 
225
253
        getauthfromURL(purl,httpauth1);
226
254
 
238
266
                        if (!(sptr = url2hostport(purl, &host, &myip, &myport))) {
239
267
                                fprintf (stderr, "Unknown host \"%s\".\n",
240
268
                                        host ? host : "");
241
 
                                exit (1);
 
269
                               sock = -1;
 
270
                               goto exit;
242
271
                        }
243
272
                        strcat (request, sptr);
244
273
                }
249
278
                        sprintf(request + strlen(request),
250
279
                                "Host: %s:%u\r\n", host, myport);
251
280
                        free (host);
 
281
                       host = NULL;
252
282
                }
253
283
 
254
284
                strcat (request, ACCEPT_HEAD);
257
287
                server.sin_addr.s_addr = myip;
258
288
                if ((sock = socket(PF_INET, SOCK_STREAM, 6)) < 0) {
259
289
                        perror ("socket");
260
 
                        exit (1);
 
290
                       goto exit;
261
291
                }
262
292
                if (connect(sock, (struct sockaddr *)&server, sizeof(server))) {
263
293
                        perror ("connect");
264
 
                        exit (1);
 
294
                       close(sock);
 
295
                       sock = -1;
 
296
                       goto exit;
265
297
                }
266
298
 
267
299
                if (strlen(httpauth1) || httpauth) {
279
311
                writestring (sock, request);
280
312
                if (!(myfile = fdopen(sock, "rb"))) {
281
313
                        perror ("fdopen");
282
 
                        exit (1);
 
314
                       close(sock);
 
315
                       sock = -1;
 
316
                       goto exit;
283
317
                };
284
318
                relocate = FALSE;
285
319
                purl[0] = '\0';
286
 
                readstring (request, linelength-1, myfile);
 
320
                if (readstring (request, linelength-1, myfile)
 
321
                    == linelength-1) {
 
322
                        fprintf(stderr, "Command exceeds max. length\n");
 
323
                        close(sock);
 
324
                        sock = -1;
 
325
                        goto exit;
 
326
                }
287
327
                if ((sptr = strchr(request, ' '))) {
288
328
                        switch (sptr[1]) {
289
329
                                case '3':
291
331
                                case '2':
292
332
                                        break;
293
333
                                default:
294
 
                                        fprintf (stderr, "HTTP request failed: %s",
295
 
                                                sptr+1); /* '\n' is included */
296
 
                                        exit (1);
 
334
                                       fprintf (stderr,
 
335
                                                "HTTP request failed: %s",
 
336
                                                sptr+1); /* '\n' is included */
 
337
                                       close(sock);
 
338
                                       sock = -1;
 
339
                                       goto exit;
297
340
                        }
298
341
                }
299
342
                do {
300
 
                        readstring (request, linelength-1, myfile);
 
343
                        if (readstring (request, linelength-1, myfile)
 
344
                            == linelength-1) {
 
345
                                fprintf(stderr, "URL exceeds max. length\n");
 
346
                                close(sock);
 
347
                                sock = -1;
 
348
                                goto exit;
 
349
                        }
301
350
                        if (!strncmp(request, "Location:", 9))
302
351
                                strncpy (purl, request+10, 1023);
303
352
                } while (request[0] != '\r' && request[0] != '\n');
304
353
        } while (relocate && purl[0] && numrelocs++ < 5);
305
354
        if (relocate) {
306
355
                fprintf (stderr, "Too many HTTP relocations.\n");
307
 
                exit (1);
 
356
               close(sock);
 
357
               sock = -1;
308
358
        }
 
359
exit:
 
360
       if (host)
 
361
               free(host);
309
362
        free (purl);
310
363
        free (request);
311
364
 
312
365
        return sock;
313
366
}
314
367
 
315
 
#else
 
368
#else /* defined(WIN32) || defined(GENERIC) */
316
369
#include <stdlib.h>
317
370
#include <stdio.h>
318
371
#include <string.h>
325
378
{
326
379
}
327
380
 
328
 
void readstring (char *string, int maxlen, FILE *f)
 
381
int readstring (char *string, int maxlen, FILE *f)
329
382
{
330
383
}
331
384