* [PATCH] unpack-trees.c: check return value of lstat()
@ 2011-03-06 19:13 Torsten Bögershausen
2011-03-06 19:29 ` Matthieu Moy
0 siblings, 1 reply; 5+ messages in thread
From: Torsten Bögershausen @ 2011-03-06 19:13 UTC (permalink / raw)
To: drizzd, git; +Cc: tboegi
Since commit f66caa "do not overwrite files in leading path"
at one place lstat() was called but the result was not checked.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
(While I was experimenting with something different,
this was found by valgrind)
Please review the patch, comments wellcome.
unpack-trees.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 1ca41b1..42f7aad 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1374,10 +1374,9 @@ static int verify_absent_1(struct cache_entry *ce,
char path[PATH_MAX + 1];
memcpy(path, ce->name, len);
path[len] = 0;
- lstat(path, &st);
-
- return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
- error_type, o);
+ if (!lstat(path, &st))
+ return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
+ error_type, o);
} else if (!lstat(ce->name, &st))
return check_ok_to_remove(ce->name, ce_namelen(ce),
ce_to_dtype(ce), ce, &st,
--
1.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] unpack-trees.c: check return value of lstat()
2011-03-06 19:13 [PATCH] unpack-trees.c: check return value of lstat() Torsten Bögershausen
@ 2011-03-06 19:29 ` Matthieu Moy
2011-03-06 19:50 ` Torsten Bögershausen
0 siblings, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2011-03-06 19:29 UTC (permalink / raw)
To: Torsten Bögershausen; +Cc: drizzd, git
Torsten Bögershausen <tboegi@web.de> writes:
> + if (!lstat(path, &st))
> + return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
> + error_type, o);
> } else if (!lstat(ce->name, &st))
What happens if lstat returns a non-0 value?
Anyway, this seems to have been fixed by a93e53018 (Wed Jan 12 20:28:09
2011, unpack-trees: handle lstat failure for existing file) already.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] unpack-trees.c: check return value of lstat()
2011-03-06 19:29 ` Matthieu Moy
@ 2011-03-06 19:50 ` Torsten Bögershausen
2011-03-06 20:57 ` Matthieu Moy
0 siblings, 1 reply; 5+ messages in thread
From: Torsten Bögershausen @ 2011-03-06 19:50 UTC (permalink / raw)
To: Matthieu Moy; +Cc: Torsten Bögershausen, drizzd, git
On 06.03.11 20:29, Matthieu Moy wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
>
>> + if (!lstat(path, &st))
>> + return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
>> + error_type, o);
>> } else if (!lstat(ce->name, &st))
>
> What happens if lstat returns a non-0 value?
The result of "st" is 100% garbage, and should not be passed to anybody.
Not checking the return value (error or not) is not a good thing.
Developers might be tempted to write unreliable code...
>
> Anyway, this seems to have been fixed by a93e53018 (Wed Jan 12 20:28:09
> 2011, unpack-trees: handle lstat failure for existing file) already.
>
Hm,
v1.7.4 says:
commit e39212ab08e8d37dda5d8fd32b54099fe01dbbdb
Merge: 716958c 9e08273
(so far so good)
My git looks like this:
static int verify_absent_1(struct cache_entry *ce,
enum unpack_trees_error_types error_type,
struct unpack_trees_options *o)
{
[snip]
else if (len > 0) {
char path[PATH_MAX + 1];
memcpy(path, ce->name, len);
path[len] = 0;
lstat(path, &st);
^^^^^^^^^^^^^^^^^^
return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
error_type, o);
(And I had to correct drizzd@aon.a -> drizzd@aon.at)
/Torsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] unpack-trees.c: check return value of lstat()
2011-03-06 19:50 ` Torsten Bögershausen
@ 2011-03-06 20:57 ` Matthieu Moy
2011-03-07 15:59 ` Torsten Bögershausen
0 siblings, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2011-03-06 20:57 UTC (permalink / raw)
To: Torsten Bögershausen; +Cc: drizzd, git
Torsten Bögershausen <tboegi@web.de> writes:
> On 06.03.11 20:29, Matthieu Moy wrote:
>> Torsten Bögershausen <tboegi@web.de> writes:
>>
>>> + if (!lstat(path, &st))
>>> + return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
>>> + error_type, o);
>>> } else if (!lstat(ce->name, &st))
>>
>> What happens if lstat returns a non-0 value?
> The result of "st" is 100% garbage, and should not be passed to
> anybody.
With your code, you don't do a return, you'll reach the end of the
function without calling return, which is probably the worst thing you
could expect.
> v1.7.4 says:
> commit e39212ab08e8d37dda5d8fd32b54099fe01dbbdb
> Merge: 716958c 9e08273
You've cut the date:
commit e39212ab08e8d37dda5d8fd32b54099fe01dbbdb
Merge: 716958c 9e08273
Author: Junio C Hamano <gitster@pobox.com>
Date: Wed Dec 22 14:40:26 2010 -0800
=> no big surprise that you don't see the bugfix from Jan 12th.
>> Anyway, this seems to have been fixed by a93e53018 (Wed Jan 12 20:28:09
>> 2011, unpack-trees: handle lstat failure for existing file) already.
Did you look at the content of this commit?
> (And I had to correct drizzd@aon.a -> drizzd@aon.at)
Yes, because you've mis-spelled it in the first place and I didn't fix
it ;-).
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] unpack-trees.c: check return value of lstat()
2011-03-06 20:57 ` Matthieu Moy
@ 2011-03-07 15:59 ` Torsten Bögershausen
0 siblings, 0 replies; 5+ messages in thread
From: Torsten Bögershausen @ 2011-03-07 15:59 UTC (permalink / raw)
To: Matthieu Moy; +Cc: Torsten Bögershausen, drizzd, git
On 06.03.11 21:57, Matthieu Moy wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
>
>> On 06.03.11 20:29, Matthieu Moy wrote:
>>> Torsten Bögershausen <tboegi@web.de> writes:
>>>
>>>> + if (!lstat(path, &st))
>>>> + return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
>>>> + error_type, o);
>>>> } else if (!lstat(ce->name, &st))
>>>
>>> What happens if lstat returns a non-0 value?
>> The result of "st" is 100% garbage, and should not be passed to
>> anybody.
>
> With your code, you don't do a return, you'll reach the end of the
> function without calling return, which is probably the worst thing you
> could expect.
>
>> v1.7.4 says:
>> commit e39212ab08e8d37dda5d8fd32b54099fe01dbbdb
>> Merge: 716958c 9e08273
>
> You've cut the date:
>
> commit e39212ab08e8d37dda5d8fd32b54099fe01dbbdb
> Merge: 716958c 9e08273
> Author: Junio C Hamano <gitster@pobox.com>
> Date: Wed Dec 22 14:40:26 2010 -0800
>
> => no big surprise that you don't see the bugfix from Jan 12th.
>
>>> Anyway, this seems to have been fixed by a93e53018 (Wed Jan 12 20:28:09
>>> 2011, unpack-trees: handle lstat failure for existing file) already.
>
> Did you look at the content of this commit?
>
>> (And I had to correct drizzd@aon.a -> drizzd@aon.at)
>
> Yes, because you've mis-spelled it in the first place and I didn't fix
> it ;-).
>
Ojojo,
While working with the best tracking tool, I lost tracking myself.
That's why I missed Jonathans fix and learned today 9e08273 != a93e53018
Thanks for the patience, (and sorry for the noise)
/Torsten
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-03-07 15:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-06 19:13 [PATCH] unpack-trees.c: check return value of lstat() Torsten Bögershausen
2011-03-06 19:29 ` Matthieu Moy
2011-03-06 19:50 ` Torsten Bögershausen
2011-03-06 20:57 ` Matthieu Moy
2011-03-07 15:59 ` Torsten Bögershausen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).