mirror of
https://github.com/curl/curl.git
synced 2024-12-09 06:30:06 +08:00
mime: avoid using access()
If stat() fails, there is no point in calling access() Also: return error immediately if the stat() fails. Ref: #13482 Closes #13497
This commit is contained in:
parent
b06619d0a3
commit
fc81bf42be
53
lib/mime.c
53
lib/mime.c
@ -1413,36 +1413,35 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename)
|
||||
char *base;
|
||||
struct_stat sbuf;
|
||||
|
||||
if(stat(filename, &sbuf) || access(filename, R_OK))
|
||||
if(stat(filename, &sbuf))
|
||||
result = CURLE_READ_ERROR;
|
||||
|
||||
part->data = strdup(filename);
|
||||
if(!part->data)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
||||
part->datasize = -1;
|
||||
if(!result && S_ISREG(sbuf.st_mode)) {
|
||||
part->datasize = filesize(filename, sbuf);
|
||||
part->seekfunc = mime_file_seek;
|
||||
}
|
||||
|
||||
part->readfunc = mime_file_read;
|
||||
part->freefunc = mime_file_free;
|
||||
part->kind = MIMEKIND_FILE;
|
||||
|
||||
/* As a side effect, set the filename to the current file's base name.
|
||||
It is possible to withdraw this by explicitly calling
|
||||
curl_mime_filename() with a NULL filename argument after the current
|
||||
call. */
|
||||
base = strippath(filename);
|
||||
if(!base)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
else {
|
||||
CURLcode res = curl_mime_filename(part, base);
|
||||
part->data = strdup(filename);
|
||||
if(!part->data)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
else {
|
||||
part->datasize = -1;
|
||||
if(S_ISREG(sbuf.st_mode)) {
|
||||
part->datasize = filesize(filename, sbuf);
|
||||
part->seekfunc = mime_file_seek;
|
||||
}
|
||||
|
||||
if(res)
|
||||
result = res;
|
||||
free(base);
|
||||
part->readfunc = mime_file_read;
|
||||
part->freefunc = mime_file_free;
|
||||
part->kind = MIMEKIND_FILE;
|
||||
|
||||
/* As a side effect, set the filename to the current file's base name.
|
||||
It is possible to withdraw this by explicitly calling
|
||||
curl_mime_filename() with a NULL filename argument after the current
|
||||
call. */
|
||||
base = strippath(filename);
|
||||
if(!base)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
else {
|
||||
result = curl_mime_filename(part, base);
|
||||
free(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user