Glibc change exposing bugs
Glibc change exposing bugs
Posted Nov 10, 2010 19:46 UTC (Wed) by rodgerd (guest, #58896)In reply to: Glibc change exposing bugs by clugstj
Parent article: Glibc change exposing bugs
Posted Nov 10, 2010 20:03 UTC (Wed)
by corbet (editor, #1)
[Link] (37 responses)
I don't believe that Linus (or anybody else) is saying that the broken applications are not buggy. What I'm hearing is that those applications have worked for years and that people should think for a long time before introducing a change which breaks them. Thus, Linus asks: what's the benefit that justifies such a change? I think it's a reasonable question.
Posted Nov 10, 2010 20:10 UTC (Wed)
by jwb (guest, #15467)
[Link] (18 responses)
Posted Nov 10, 2010 20:38 UTC (Wed)
by neilbrown (subscriber, #359)
[Link] (17 responses)
So implementing memcpy as memmove - which Linus says in the bugzilla threads is largely what the kernel does - sounds very sensible. memmove is much harder to misuse.
Posted Nov 13, 2010 1:07 UTC (Sat)
by rriggs (guest, #11598)
[Link] (3 responses)
Which one do you think your average C programmer will choose?
Which one do you think new programmers are taught to use (in schools that still teach C programming)?
Posted Nov 13, 2010 2:52 UTC (Sat)
by neilbrown (subscriber, #359)
[Link] (1 responses)
Posted Nov 15, 2010 16:43 UTC (Mon)
by renox (guest, #23785)
[Link]
And memcpy should also be named as mem_unsafe_copy, but yes if you tell developers to use safe function by default and to optimize only when they can show benchmarks that the optimisation will make a difference, then yes, you'd get probably better software (if a bit slower).
Posted Oct 17, 2013 12:49 UTC (Thu)
by jzbiciak (guest, #5246)
[Link]
You're calling memmove verbose as compared to memcpy? Even Ken Thompson said if he had it to do over, he'd spell creat() with the final 'e'.
Posted Nov 25, 2010 15:13 UTC (Thu)
by Spudd86 (subscriber, #51683)
[Link] (2 responses)
The problem is that most apps don't actually need the those bits, so they just needlessly break software like pulseaudio (and also break on bluetooth audio too).
Pulseaudio does use those unemulatable APIs, but it also falls back if they don't work, and it has good reasons to use those APIs (so it can hand over large chunks of audio data, but still be able to decide it wants to change that same data later (if for example something else starts playing audio), this saves you power because pulse won't wake your CPU as much, but it also uses APIs that don't emulate well AND until pulse came along nobody ever tried to do that sort of thing so it broke)
Posted Nov 25, 2010 16:07 UTC (Thu)
by foom (subscriber, #14868)
[Link] (1 responses)
Posted Nov 25, 2010 16:39 UTC (Thu)
by Spudd86 (subscriber, #51683)
[Link]
Posted Oct 17, 2013 12:42 UTC (Thu)
by jzbiciak (guest, #5246)
[Link] (9 responses)
One major reason the remaining distinction between memcpy and memmove exists in the standard seems to be this: To write memmove completely within conformant C, you need a malloc and a double-copy. That's because in that mythical Platonic ideal of a language, you cannot compare two pointers that do not point into the same object, and you are not guaranteed that the arguments to memmove point within the same object. That is, a fully compliant memmove would look something like this:
And, on 16-bit segmented computers or other computers lacking flat memory spaces, both of which are rather from a Platonic ideal, comparing two pointers isn't always as straightforward as you might like. So practically, memcpy offers some noticeable performance benefits on those machines. Yes, I'm aware that the actual language in the standard says 'as if' the source was first copied to a temporary array. But, as I recall, a fully conformant C program has no other option. The 'as-if' clause allows library writers to avoid such shenanigans, without requiring them to do so. So much hair-splitting... If it weren't for that, you could make the argument that separate memcpy and memmove were historical accidents, and change the C standard at some point to remove the restrictions on memcpy to make them both equivalent. That new memcpy would then adhere to Rusty's Maxim, or at least come much closer. And, from the thread linked above, that's pretty much what BSD did, it sounds like.
As a half step, you could define memcpy as always copying forward, to make "sliding down" safe, but that just seems a little goofy for a number of reasons. I'm personally with Linus that the glibc breakage seems gratuitous. I'd lean towards making memcpy and memmove equivalent if their performance is largely indistinguishable. Arguing that the software is broken when it worked for year with the old library reminds me of this silly meme. It's the kind of hair-splitting that only a bureaucrat or chapter-verser could love.
Posted Oct 17, 2013 12:44 UTC (Thu)
by jzbiciak (guest, #5246)
[Link] (8 responses)
...rather far from a Platonic ideal... Need. More. Coffee.
Posted Oct 18, 2013 13:31 UTC (Fri)
by meuh (guest, #22042)
[Link] (7 responses)
If we were on "stackoverflow", you would have earned the "Necromancer" badge ;)
Posted Oct 18, 2013 14:08 UTC (Fri)
by jzbiciak (guest, #5246)
[Link] (6 responses)
Posted Oct 21, 2013 20:37 UTC (Mon)
by nix (subscriber, #2304)
[Link] (5 responses)
Posted Oct 21, 2013 20:49 UTC (Mon)
by khim (subscriber, #9252)
[Link] (4 responses)
Note that in real world there are no such guarantee (hint, hint) thus GLibC's memmove sometimes works and sometimes does not work.
Posted Oct 23, 2013 14:23 UTC (Wed)
by nix (subscriber, #2304)
[Link] (3 responses)
This behaviour is explicitly permitted by the Standard: segmented architectures like MS-DOS were like this decades ago. The guarantee that a == b returns nonzero only when a and b are pointers to the same object holds nonetheless. It's just a less useful guarantee than we might like.
Posted Oct 23, 2013 15:47 UTC (Wed)
by khim (subscriber, #9252)
[Link] (2 responses)
My point was that real-world GLibC-implemented memmove does not actually work when used on POSIX system. It compares pointers and assumes that if they are different then underlying memory is also different! Which means, strictly speaking, that memmove in GLibC is not standards-compliant :-)
Posted Oct 23, 2013 16:47 UTC (Wed)
by jzbiciak (guest, #5246)
[Link]
Posted Oct 23, 2013 18:09 UTC (Wed)
by nix (subscriber, #2304)
[Link]
... bloody hell, it does. Or many of the assembler versions do anyway. Or, rather, it assumes that distinct addresses cannot alias.
I suppose this is probably safe in practice, because if you *do* use mmap() to set up aliased regions at distinct addresses you are suddenly in hardware-dependent land (due to machines with VIPT caches such as, IIRC, MIPS, not being able to detect such aliasing at the caching level, so you suddenly need to introduce -- necessarily hardware-dependent -- cache flushes and memory barriers) so you have to know what you're doing anyway, and little things like memmove() falling back to memcpy() at unexpected times are things you're supposed to know about.
I hope.
Posted Nov 10, 2010 20:56 UTC (Wed)
by clugstj (subscriber, #4020)
[Link] (8 responses)
Posted Nov 10, 2010 22:24 UTC (Wed)
by lmb (subscriber, #39048)
[Link] (6 responses)
That behavior is undefined makes one only right as far as technicality is concerned; it does not imply that changing it silently is good software engineering practice, nor that it is right in terms of software providing a service to users.
Posted Nov 10, 2010 23:58 UTC (Wed)
by nix (subscriber, #2304)
[Link] (4 responses)
Posted Nov 11, 2010 2:29 UTC (Thu)
by foom (subscriber, #14868)
[Link] (3 responses)
Posted Nov 11, 2010 7:29 UTC (Thu)
by nix (subscriber, #2304)
[Link] (2 responses)
Posted Nov 11, 2010 17:30 UTC (Thu)
by foom (subscriber, #14868)
[Link] (1 responses)
Here we have a new bug in flash which appeared without a new version of the flash binary being uploaded. It's a substantively different situation.
Posted Nov 12, 2010 7:12 UTC (Fri)
by hozelda (guest, #19341)
[Link]
If you are that worried, you should work off stable versions or off a stable distributor that will manage this for you. You should not change key parts of the system if possible. glibc is a very key part. You should not update for optimizations, at least not without significant tests and only if you think it's worthwhile the gains. Stick to security updates or when a crucial problem has been solved.
Anyway, when an important "bug" like this comes up, projects should audit the code. In this case, the possible entry points to potential problems can be identified quickly for many projects (just search for memcpy).
The case of glibc involves well-defined standards. Most libraries do not have such carefully defined semantics, and we must rely on access to source code for the juicy bits.
OK, despite what I just said, if the gains here are not that useful, glibc should revert, at least for the time being. Reverting should not hurt those that adjusted already and will save those that have not. On the other hand, when will be the right time to change? Will people remember to fix this problem or will we just have a repeat later on? [Again, if the gains are negligible, the change in glibc should probably be avoided.]
Posted Nov 11, 2010 0:50 UTC (Thu)
by MattPerry (guest, #46341)
[Link]
But it is defined. The man page says not to use that function on overlapping regions. That applications ignored that and still functioned for so long is more a matter of good luck. That luck has run out due to their poor implementations and they should now be fixed.
Posted Nov 11, 2010 1:15 UTC (Thu)
by Lovechild (guest, #3592)
[Link]
Posted Nov 11, 2010 2:41 UTC (Thu)
by quotemstr (subscriber, #45331)
[Link] (8 responses)
memcpy, on the other hand, is clearly described by the relevant standards. Application developers deserve what they get.
Posted Nov 11, 2010 8:07 UTC (Thu)
by bojan (subscriber, #14302)
[Link] (7 responses)
He, he... Nice try :-)
Nothing could be further from the truth. The problem is that the standard doesn't _specify_ in which order things should happen on the underlying FS, which then gives implementers the ability to implement _any_ order (which they do). Relying on a _particular_ order (which is completely undocumented, of course) by application writers is the problem.
Suggestion about specification not dealing with crashes is irrelevant, because, once again, it doesn't specify _any_ behaviour. In other words, if you FS is hosed completely after a crash, that OK. If it's half hosed, that's OK too. If it's completely OK, that's OK as well. Obviously, the _interesting_ case is when it's completely OK, in which case the _implemented_ ordering actually makes a difference. And, once again, _any_ ordering is OK, because the standard specifies _none_.
The only difference between this and the memcpy() fiasco is that in the case of rename() folks may get an _impression_ that the operation is atomic on the FS level, because it is atomic as viewed from the processes currently running on the system. Of course, this is documented nowhere, but is a common misreading of the standard.
With memcpy() it is quite clear overlapping regions should be copied with memmove().
Posted Nov 11, 2010 8:32 UTC (Thu)
by Mook (subscriber, #71173)
[Link] (6 responses)
Yes, glibc's rename() API guarantees atomic renames. Since normal applications do not make syscalls directly, but call the libc API to do it on their behalf, they are not to blame.
Posted Nov 11, 2010 8:46 UTC (Thu)
by bojan (subscriber, #14302)
[Link] (5 responses)
The atomicity of rename() refers to a view from the running system and not much else. But it has sure been misread a lot :-)
Posted Nov 11, 2010 9:06 UTC (Thu)
by Mook (subscriber, #71173)
[Link] (4 responses)
Posted Nov 11, 2010 9:52 UTC (Thu)
by bojan (subscriber, #14302)
[Link] (3 responses)
Posted Nov 11, 2010 13:49 UTC (Thu)
by pbonzini (subscriber, #60935)
[Link] (2 responses)
Posted Nov 11, 2010 23:05 UTC (Thu)
by bojan (subscriber, #14302)
[Link] (1 responses)
What glibc docs are talking about is that rename() is not implemented by copying content of the oldname to newname. So, if there was newname before rename and the directory commit doesn't go through, the content of newname will not be changed. It is a pure directory operation. On the other hand, if the directory gets committed, there will be just newname there, pointing to whatever content oldname had. All of that is if your FS knows how to survive a crash - otherwise situation is not interesting (well, unless you're the sysadmin recovering the mess :-).
Now note the situation from the ext4 "problem". The oldname content was not fsync()-ed to disk before the rename(). Ergo, when the directory got committed, oldname became newname on disk, pointing to zero bytes, due to delayed allocation. This has nothing to do with the fact that on unsuccessful (i.e. not committed before the crash) rename(), both oldname and newname would remain in the directory.
Posted Nov 12, 2010 7:12 UTC (Fri)
by Mook (subscriber, #71173)
[Link]
Posted Nov 10, 2010 20:07 UTC (Wed)
by dlang (guest, #313)
[Link] (51 responses)
if a userspace program does things that have been working, even if they weren't supposed to work, that's part of the ABI of the kernel and he is very reluctant to change anything, and will only do so when there is a _very_ compelling reason
Posted Nov 10, 2010 20:36 UTC (Wed)
by JoeBuck (subscriber, #2330)
[Link] (50 responses)
An alternative LD_PRELOAD, pointing to a memcpy that crashes for overlapping arguments, could be used to expose accidental misuse of the API.
Posted Nov 10, 2010 20:51 UTC (Wed)
by clugstj (subscriber, #4020)
[Link]
Posted Nov 10, 2010 22:47 UTC (Wed)
by khim (subscriber, #9252)
[Link] (2 responses)
The actual cite: Linus is Ok with changes that break buggy programs (it happened before, it'll happen again) bit only if there are "major reason". What's the justification for this particular case?
Posted Nov 10, 2010 23:17 UTC (Wed)
by bojan (subscriber, #14302)
[Link] (1 responses)
Linus couldn't play his favourite YouTube videos ;-)
Posted Nov 11, 2010 1:31 UTC (Thu)
by jonabbey (guest, #2736)
[Link]
It's not, in fact, a bug. It's a feature.
Posted Nov 10, 2010 23:15 UTC (Wed)
by charlieb (guest, #23340)
[Link] (45 responses)
Does it? The man page says:
The memory areas should not overlap.
It does not say:
The memory areas must not overlap.
It also says:
The memcpy() function copies n bytes from memory area src to
It doesn't say:
The memcpy() function copies n bytes from memory area src to
"should" provisions are not mandatory. Unless you decide to redefine the terminology.
Posted Nov 10, 2010 23:23 UTC (Wed)
by bojan (subscriber, #14302)
[Link]
> Use memmove(3) if the memory areas do overlap.
Posted Nov 10, 2010 23:24 UTC (Wed)
by donwaugaman (subscriber, #4214)
[Link] (42 responses)
If copying takes place between objects that overlap, the behavior is undefined.
In the context of standardese, that specifies that exactly anything can happen in the event of overlapping memory areas, with no 'should' or 'must' about it. The standard doesn't set down any rules that a developer must follow, only what will happen under certain conditions (in this case, the result is 'anything').
'must' and 'should' are more in the vein of RFCs.
Posted Nov 11, 2010 0:25 UTC (Thu)
by nicooo (guest, #69134)
[Link] (38 responses)
Glibc's info page says it's undefined. It's the official documentation but nobody uses info.
Posted Nov 11, 2010 0:28 UTC (Thu)
by bojan (subscriber, #14302)
[Link]
Posted Nov 11, 2010 0:33 UTC (Thu)
by charlieb (guest, #23340)
[Link]
Ideally the linux man-page will be clarified. "should" there seems just a recommendation. Not "your software will eat babies unless you do this".
Posted Nov 11, 2010 2:42 UTC (Thu)
by butlerm (subscriber, #13312)
[Link] (35 responses)
Posted Nov 11, 2010 6:41 UTC (Thu)
by HelloWorld (guest, #56129)
[Link] (25 responses)
Posted Nov 11, 2010 9:46 UTC (Thu)
by mpr22 (subscriber, #60784)
[Link] (12 responses)
Posted Nov 11, 2010 22:47 UTC (Thu)
by vonbrand (subscriber, #4458)
[Link] (1 responses)
Try pinfo
Posted Nov 12, 2010 14:08 UTC (Fri)
by jzbiciak (guest, #5246)
[Link]
Posted Nov 11, 2010 22:56 UTC (Thu)
by HelloWorld (guest, #56129)
[Link] (8 responses)
Posted Nov 12, 2010 18:19 UTC (Fri)
by sorpigal (guest, #36106)
[Link] (1 responses)
I've used pinfo and it helps some in the UI department, but I'd still use man over pinfo for almost every trivial lookup. If your goal is to completely replace man then your system needs to be a drop-in replacement from a user interaction point of view, with the advantages discoverable by users who are interested in learning them.
Posted Nov 12, 2010 18:45 UTC (Fri)
by foom (subscriber, #14868)
[Link]
Not really: "info" also searches the whole document if you hit /. (although I share the general dislike for the info browser).
Posted Nov 25, 2010 15:22 UTC (Thu)
by Spudd86 (subscriber, #51683)
[Link] (5 responses)
It'd be nice to have an info viewer that converts to HTML on the fly and uses webkit to render it.
Posted Nov 25, 2010 22:13 UTC (Thu)
by paulj (subscriber, #341)
[Link] (4 responses)
Posted Nov 26, 2010 0:31 UTC (Fri)
by Spudd86 (subscriber, #51683)
[Link] (3 responses)
Posted Nov 26, 2010 0:40 UTC (Fri)
by sfeam (subscriber, #2841)
[Link] (2 responses)
Posted Nov 26, 2010 1:33 UTC (Fri)
by Spudd86 (subscriber, #51683)
[Link] (1 responses)
Posted Nov 27, 2010 13:26 UTC (Sat)
by paulj (subscriber, #341)
[Link]
Posted Nov 12, 2010 10:36 UTC (Fri)
by marcH (subscriber, #57642)
[Link]
Posted Nov 12, 2010 5:01 UTC (Fri)
by nicooo (guest, #69134)
[Link] (5 responses)
Posted Nov 12, 2010 7:33 UTC (Fri)
by paulj (subscriber, #341)
[Link]
Posted Nov 12, 2010 10:42 UTC (Fri)
by marcH (subscriber, #57642)
[Link]
I find it too bad that a not-so-good default user interface is rebuffing users before then even start to see the nice features of the format. The fix is to promote alternatives user interfaces, something I keep doing constantly (and which has already been done here).
Posted Nov 12, 2010 13:59 UTC (Fri)
by HelloWorld (guest, #56129)
[Link] (1 responses)
Posted Nov 12, 2010 20:10 UTC (Fri)
by nicooo (guest, #69134)
[Link]
Posted Nov 12, 2010 23:32 UTC (Fri)
by Wol (subscriber, #4433)
[Link]
Which is why I like man, and like pdf, and just curse profusely every time I'm exhorted to use info!
Cheers,
Posted Nov 12, 2010 13:52 UTC (Fri)
by Wol (subscriber, #4433)
[Link] (5 responses)
At least with man, I can scroll down (or search) until I find what I'm looking for.
info, on the other hand, "you are in maze of twisty little passages all alike". When presented with the instruction to "use info", I give up and use the web. When presented with a 1000-line man page, no problem ... :-)
Cheers,
Posted Nov 12, 2010 14:06 UTC (Fri)
by HelloWorld (guest, #56129)
[Link] (4 responses)
> At least with man, I can scroll down (or search) until I find what I'm looking for.
Posted Nov 12, 2010 19:11 UTC (Fri)
by bronson (subscriber, #4806)
[Link]
Take a deep breath dude. Different people like different things.
Posted Nov 12, 2010 23:39 UTC (Fri)
by Wol (subscriber, #4433)
[Link] (2 responses)
The problem with that is if I can't articulate what I'm searching for. The number of times I've searched on what I think is the obvious search key, wasted half-an-hour or so doing it, then done a manual scroll through whatever I can find.
I then find what I'm looking for, and discover that it's called something (to me) extremely obscure, and doesn't mention my search term at all, etc etc.
Plus the fact that I'm one of those strange people who actually DOES tend to read documentation, from cover to cover, and likes to have a straight line path through it, not with redirects and jumps and god knows what all over the place. About the only place I can find information on info is in info - and if I find info repellent, how on earth am I going to find out how to use it if I have to use it to find out?
THERE is your problem with info - if you hate it because you can't find out how to use it, it's catch 22. You need to know how to use it to find out how to use it :-)
Cheers,
Posted Nov 13, 2010 0:42 UTC (Sat)
by foom (subscriber, #14868)
[Link] (1 responses)
Posted Nov 14, 2010 22:32 UTC (Sun)
by nix (subscriber, #2304)
[Link]
Posted Nov 11, 2010 7:31 UTC (Thu)
by nix (subscriber, #2304)
[Link] (8 responses)
Posted Nov 12, 2010 7:30 UTC (Fri)
by hozelda (guest, #19341)
[Link] (7 responses)
If you use Linux, the Linux documentation should be authoritative. Hopefully, it will agree with POSIX and C99 (or whatever is the latest memcpy standard) as much as possible. If there is a reason for a change (or to document a Linux bug) and you use Linux, I would pay attention to the Linux documentation and treat everything else as advisory. If you use Red Hat or whatever other distro, I would look treat those docs as authoritative and not whatever other standard you think should apply.
A different matter is arguing about keeping Linux in sync with POSIX, etc, but if you want to build software that will work, short of maintaining your personal set of patches not accepted by upstream, you would probably want to code to "Linux" (at least for the Linux port).
Posted Nov 12, 2010 7:37 UTC (Fri)
by hozelda (guest, #19341)
[Link]
Posted Nov 14, 2010 21:19 UTC (Sun)
by nix (subscriber, #2304)
[Link] (5 responses)
(You might need to adjust for bits of older systems that are non-POSIX, but that is really quite rare these days unless you're aiming for some strange emulation layer like Cygwin. Also you might need to do byteorder detection and so forth, but, again, that's stuff which is left unspecified by POSIX. You should not generally have to use Linux-specific stuff unless you really want to, and you normally shouldn't want to.)
Posted Nov 14, 2010 22:03 UTC (Sun)
by promotion-account (guest, #70778)
[Link] (3 responses)
You should not generally have to use Linux-specific stuff unless you really want to, and you normally shouldn't want to.
I'm sure you know this, but for some applications, POSIX is not really enough. Thus, for example, the need for some portable abstraction libraries like libevent.
Posted Nov 14, 2010 23:08 UTC (Sun)
by nix (subscriber, #2304)
[Link] (2 responses)
(btw, your account name is... *interesting*.)
Posted Nov 15, 2010 1:37 UTC (Mon)
by promotion-account (guest, #70778)
[Link] (1 responses)
(btw, your account name is... *interesting*.) That's descriptive anonymity :)
Readers usually give higher weight to subscribers opinions here, so this handle honestly states that I'm a promoted guest.
Posted Nov 15, 2010 10:39 UTC (Mon)
by nix (subscriber, #2304)
[Link]
'Promotion' is a word with many meanings...
Posted Nov 15, 2010 8:13 UTC (Mon)
by dlang (guest, #313)
[Link]
most programs do not start off being written portably, usually portability is something that shows up after the program starts being used when people ask about using it on other platforms (and it's not uncommon for it to wait until those people asking submit patches)
not saying that this is right, just saying that it's the way things are. When Solaris dominated the same thing happened favoring it.
Posted Nov 11, 2010 0:30 UTC (Thu)
by charlieb (guest, #23340)
[Link] (2 responses)
What manpage is that? The memcpy(3) manpage on my CentOS4 box does not say "the behavior is undefined". Ah, I see that the memcpy(3p) one does.
> 'must' and 'should' are more in the vein of RFCs.
OK. But at least those are clear. "should" in the context of an API man page is not.
Posted Nov 11, 2010 12:23 UTC (Thu)
by gidoca (subscriber, #62438)
[Link]
Posted Nov 11, 2010 18:03 UTC (Thu)
by donwaugaman (subscriber, #4214)
[Link]
"The memory areas may not overlap."
... which sounds a little stronger than "should" to me.
Not sure why CentOS4 differs...
At any rate, arguing over the man pages is irrelevant to the standard - if the man pages don't match the standard, the man pages need to be fixed rather than the standard.
That being said, it would sure be nice to have some kind of formal deprecation of the previous behavior. One of the nice things about the free software world is that it should be more possible to make these kinds of changes because it's easier to change the programs whose assumptions worked OK with the previous behavior but are violated by the new behavior. Of course, with closed-source Flash players, that goes out the window, and it becomes a question of whether it is more important to pacify Adobe users or to give Adobe an incentive to clean up its software.
Posted Nov 11, 2010 0:04 UTC (Thu)
by nix (subscriber, #2304)
[Link]
> If copying takes place between objects that overlap, the behavior is undefined.
The behaviour of Linux (and Unix) systems in this area are governed by POSIX, not a random manpage. (And in this case POSIX is aligned with ISO C, and even uses the same phrasing.)
That's a germane example, actually. "Poo flinging" notwithstanding, the kernel developers fixed things so that applications would not lose data even if they weren't following standard behavior. Not breaking things was seen as more important than doing something because the posted rules say you can.
Glibc change exposing bugs
Glibc change exposing bugs
This all sounds like a very strong recommendation in favour of Rusty Russell's Maxim of API development: APIs should be
hard to misuse. memcpy, and apparently ALSA, are easy to misuse.
Glibc change exposing bugs
Glibc change exposing bugs
memcpy: unsafe, at least as fast as memmove, one less character to type
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
void *memmove(void *dst, const void *src, size_t len)
{
char *srcc = (char *)src;
char *dstc = (char *)dst;
char *temp = malloc(len);
size_t i;
/* What if 'malloc' fails? call abort()? Unspecified! */
for (i = 0; i != len; i++)
temp[i] = srcc[i];
for (i = 0; i != len; i++)
dstc[i] = temp[i];
free(temp);
return dst;
}
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Your comment was interesting anyway. This is the relevant guarantee from C89 (C99 and C11 have similar wording):
Glibc change exposing bugs
If two pointers to object or incomplete types compare equal, they point to the same object. If two pointers to functions compare equal, they point to the same function. If two pointers point to the same object or function, they compare equal. If one of the operands is a pointer to an object or incomplete type and the other has type pointer to a qualified or unqualified version of void , the pointer to an object or incomplete type is converted to the type of the other operand.
The problem here is that this does not guarantee that two pointers to the same object always compare equal, but rather that if they compare equal, they are pointers to the same object (and similarly for comparison operators). We can tell if two pointers definitely are pointers within the same object, but if the comparison fails we cannot conclude anything. This is unfortunately the opposite of the guarantee that memmove() needs if it is to transform itself into a memmove() when needed, so (in the absence of a Standard-blessed way to normalize pointers) you are indeed forced to do a double-copy at all times when writing memmove() in Standard C.
Glibc change exposing bugs
This is unfortunately the opposite of the guarantee that memmove() needs if it is to transform itself into a memmove() when needed, so (in the absence of a Standard-blessed way to normalize pointers) you are indeed forced to do a double-copy at all times when writing memmove() in Standard C.
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
> is concerned;
Glibc change exposing bugs
Glibc change exposing bugs
the kernel developers fixed things so that applications would not lose data even if they weren't following standard behavior
What some filesystem developers propose applications do isn't defined by any standard. POSIX, SuS, and so on don't state what happens after a crash, fsync() or not. The argument was over what to do in certain circumstances outside any standard. The argument was must muddled because one said kept claiming that its brand of brain damage was endorsed by the standard. Fortunately, sanity prevailed. Calling fsync() after every rename would have inconvenienced application developers and decreased performance.
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
The existing memcpy implementation did copying in a forward direction, so it would give a wrong result for memcpy(buf, buf + 4, 8) but the expected result for memcpy(buf, buf - 4, 8). The change (in at least some circumstances) does the reverse, and both ways satisfy the spec, which says that src and dst must not overlap, and if they might, memmove should be used. Linus is apparently calling for the original implementation decision (forward, not backward) to be set in stone, even if a backward-copy might be faster on a particular processor. This doesn't seem right to me. However, it seems reasonable to provide a cleaner workaround until old code can be fixed (it might just be a cleaned-up version of his proposed LD_PRELOAD trick).
Glibc change exposing bugs
Glibc change exposing bugs
Please don't attack strawmen. Thnx.
So in the kernel we have a pretty strict "no regressions" rule, and that if
people depend on interfaces we exported having side effects that weren't
intentional, we try to fix things so that they still work unless there is a
major reason not to.
...
Regardless, it boils down to: we know the glibc change resulted in problems for real users. We do _not_ know that it helped anything at all.Please don't attack strawmen. Thnx.
Please don't attack strawmen. Thnx.
Glibc change exposing bugs
> not overlap, ...
memory area dest.
memory area dest, unless the memory areas overlap.
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
> the linux man-pages project.
It's the official documentation but nobody uses info.Glibc change exposing bugs
That is because 'info' is user hostile and dangerously close to useless. A web search is a dozen times faster than navigating an info document.
Glibc change exposing bugs
For large manuals, my experience is that Glibc change exposing bugs
info
merely sucks less than a man page; the user interface of both /usr/bin/info
and /usr/bin/emacs -f info
is horrible. For simple things, man
wins by a country mile, because it doesn't slice-and-dice a simple program's documentation into 742 one-paragraph pages.
info considered harmful?
info considered harmful?
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
konqueror info:tar
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
- the info format
- the info reader
- how fine the writer sliced the document
Very confusing.
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Wol
Glibc change exposing bugs
Wol
Glibc change exposing bugs
So you can with info. You can search the complete manual with the s key. The fact that you don't know this indicates you don't bother to read documentation at all really.
> info, on the other hand, "you are in maze of twisty little passages all alike".
If you had actually read the headings of the "twistly little passages", you would have found that they're really not alike at all. Alas, you don't seem to have bothered and decided to pointlessly whine about info instead.
Glibc change exposing bugs
Glibc change exposing bugs
Wol
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
Glibc change exposing bugs
If "should" is interpreted the way you do, then they might as well have omitted the sentence.
Glibc change exposing bugs
Glibc change exposing bugs