]>
Commit | Line | Data |
---|---|---|
bd93d5d8 | 1 | diff -urN a2ps-4.13.orig/src/select.c a2ps-4.13/src/select.c |
2 | --- a2ps-4.13.orig/src/select.c 2004-12-13 14:32:29.582879216 +0100 | |
3 | +++ a2ps-4.13/src/select.c 2004-12-13 14:33:42.773752512 +0100 | |
4 | @@ -131,6 +131,36 @@ | |
5 | return 1; | |
6 | } | |
7 | \f | |
8 | +/* escapes the name of a file so that the shell groks it in 'single' q.marks. | |
9 | + The resulting pointer has to be free()ed when not longer used. */ | |
10 | +char * | |
11 | +shell_escape(const char *fn) | |
12 | +{ | |
13 | + size_t len = 0; | |
14 | + const char *inp; | |
15 | + char *retval, *outp; | |
16 | + | |
17 | + for(inp = fn; *inp; ++inp) | |
18 | + switch(*inp) | |
19 | + { | |
20 | + case '\'': len += 4; break; | |
21 | + default: len += 1; break; | |
22 | + } | |
23 | + | |
24 | + outp = retval = malloc(len + 1); | |
25 | + if(!outp) | |
26 | + return NULL; /* perhaps one should do better error handling here */ | |
27 | + for(inp = fn; *inp; ++inp) | |
28 | + switch(*inp) | |
29 | + { | |
30 | + case '\'': *outp++ = '\''; *outp++ = '\\'; *outp++ = '\'', *outp++ = '\''; break; | |
31 | + default: *outp++ = *inp; break; | |
32 | + } | |
33 | + *outp = 0; | |
34 | + | |
35 | + return retval; | |
36 | +} | |
37 | +\f | |
38 | /* What says file about the type of a file (result is malloc'd). NULL | |
39 | if could not be run. */ | |
40 | ||
41 | @@ -144,11 +174,15 @@ | |
42 | if (IS_EMPTY (job->file_command)) | |
43 | return NULL; | |
44 | ||
45 | + filename = shell_escape(filename); | |
46 | + if(filename == NULL) | |
47 | + return NULL; | |
48 | /* Call file(1) with the correct option */ | |
49 | - command = ALLOCA (char, (2 | |
50 | + command = ALLOCA (char, (4 | |
51 | + strlen (job->file_command) | |
52 | + ustrlen (filename))); | |
53 | - sprintf (command, "%s %s", job->file_command, (const char *) filename); | |
54 | + sprintf (command, "%s '%s'", job->file_command, (const char *) filename); | |
55 | + free(filename); | |
56 | message (msg_tool, (stderr, "Reading pipe: `%s'\n", command)); | |
57 | file_out = popen (command, "r"); | |
58 |