Lines 131-136
Link Here
|
131 |
return 1; |
131 |
return 1; |
132 |
} |
132 |
} |
133 |
|
133 |
|
|
|
134 |
/* escapes the name of a file so that the shell groks it in 'single' q.marks. |
135 |
The resulting pointer has to be free()ed when not longer used. */ |
136 |
char * |
137 |
shell_escape(const char *fn) |
138 |
{ |
139 |
size_t len = 0; |
140 |
const char *inp; |
141 |
char *retval, *outp; |
142 |
|
143 |
for(inp = fn; *inp; ++inp) |
144 |
switch(*inp) |
145 |
{ |
146 |
case '\'': len += 4; break; |
147 |
default: len += 1; break; |
148 |
} |
149 |
|
150 |
outp = retval = malloc(len + 1); |
151 |
if(!outp) |
152 |
return ""; /* perhaps one should do better error handling here */ |
153 |
for(inp = fn; *inp; ++inp) |
154 |
switch(*inp) |
155 |
{ |
156 |
case '\'': *outp++ = '\''; *outp++ = '\\'; *outp++ = '\'', *outp++ = '\''; break; |
157 |
default: *outp++ = *inp; break; |
158 |
} |
159 |
*outp = 0; |
160 |
|
161 |
return retval; |
162 |
} |
163 |
|
134 |
/* What says file about the type of a file (result is malloc'd). NULL |
164 |
/* What says file about the type of a file (result is malloc'd). NULL |
135 |
if could not be run. */ |
165 |
if could not be run. */ |
136 |
|
166 |
|
Lines 144-154
Link Here
|
144 |
if (IS_EMPTY (job->file_command)) |
174 |
if (IS_EMPTY (job->file_command)) |
145 |
return NULL; |
175 |
return NULL; |
146 |
|
176 |
|
|
|
177 |
filename = shell_escape(filename); |
147 |
/* Call file(1) with the correct option */ |
178 |
/* Call file(1) with the correct option */ |
148 |
command = ALLOCA (char, (2 |
179 |
command = ALLOCA (char, (4 |
149 |
+ strlen (job->file_command) |
180 |
+ strlen (job->file_command) |
150 |
+ ustrlen (filename))); |
181 |
+ ustrlen (filename))); |
151 |
sprintf (command, "%s %s", job->file_command, (const char *) filename); |
182 |
sprintf (command, "%s '%s'", job->file_command, (const char *) filename); |
|
|
183 |
free(filename); |
152 |
message (msg_tool, (stderr, "Reading pipe: `%s'\n", command)); |
184 |
message (msg_tool, (stderr, "Reading pipe: `%s'\n", command)); |
153 |
file_out = popen (command, "r"); |
185 |
file_out = popen (command, "r"); |