diff options
author | H. Peter Anvin <hpa@zytor.com> | 2009-04-06 15:19:21 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2009-04-06 15:19:21 -0700 |
commit | 2920515b1fe5dbf20cfa2f2890b154cd147831ec (patch) | |
tree | b60d63da0dc91bfd3b134233319b4ee19fc0873a /com32/lib/syslinux/setadv.c | |
parent | c2636af9b7f4b170ffe791d5008fe6bdd822a59b (diff) | |
download | syslinux-3.74-pre18.tar.gz |
Implement MENU SAVE; fix COM32 setadv functionsyslinux-3.74-pre18
Implement MENU SAVE, which allows the menu system to retain the
previous selection from one boot to another. In the process, fix the
syslinux_setadv() function.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/lib/syslinux/setadv.c')
-rw-r--r-- | com32/lib/syslinux/setadv.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/com32/lib/syslinux/setadv.c b/com32/lib/syslinux/setadv.c index 4af8d6e1..5993df6d 100644 --- a/com32/lib/syslinux/setadv.c +++ b/com32/lib/syslinux/setadv.c @@ -1,6 +1,7 @@ /* ----------------------------------------------------------------------- * * * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved + * Copyright 2009 Intel Corporation; author: H. Peter Anvin * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -47,7 +48,7 @@ int syslinux_setadv(int tag, size_t size, const void *data) { uint8_t *p, *advtmp; - size_t left; + size_t rleft, left; if ((unsigned)tag-1 > 254) { errno = EINVAL; @@ -59,11 +60,11 @@ int syslinux_setadv(int tag, size_t size, const void *data) return -1; } - left = syslinux_adv_size(); + rleft = left = syslinux_adv_size(); p = advtmp = alloca(left); memcpy(p, syslinux_adv_ptr(), left); /* Make working copy */ - while (left >= 2) { + while (rleft >= 2) { uint8_t ptag = p[0]; size_t plen = p[1]+2; @@ -73,17 +74,19 @@ int syslinux_setadv(int tag, size_t size, const void *data) if (ptag == tag) { /* Found our tag. Delete it. */ - if (plen >= left) { + if (plen >= rleft) { /* Entire remainder is our tag */ break; } - memmove(p, p+plen, left-plen); + memmove(p, p+plen, rleft-plen); + rleft -= plen; /* Fewer bytes to read, but not to write */ } else { /* Not our tag */ - if (plen > left) + if (plen > rleft) break; /* Corrupt tag (overrun) - overwrite it */ left -= plen; + rleft -= plen; p += plen; } } @@ -100,6 +103,7 @@ int syslinux_setadv(int tag, size_t size, const void *data) *p++ = tag; *p++ = size; memcpy(p, data, size); + p += size; left -= size+2; } |