summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorC. Davis <cd.rattan@gmail.com>2012-08-19 19:11:16 -0700
committerMichael Adam <obnox@samba.org>2013-04-29 13:07:54 +0200
commit8ea38ce970d7539c25d4da08065d6bfa999f3e96 (patch)
tree17d68242f17a8535bf4e3d6554e8cefd7cd882c9 /source3/utils
parentad15a83357dccc9a41ade1642cca24a0b7de92df (diff)
downloadsamba-8ea38ce970d7539c25d4da08065d6bfa999f3e96.tar.gz
samba-8ea38ce970d7539c25d4da08065d6bfa999f3e96.tar.bz2
samba-8ea38ce970d7539c25d4da08065d6bfa999f3e96.zip
regedit: Handle zero-length buffers better with hexedit.
Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/regedit_dialog.c2
-rw-r--r--source3/utils/regedit_hexedit.c19
2 files changed, 19 insertions, 2 deletions
diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c
index 08b746b5f7..d05efad142 100644
--- a/source3/utils/regedit_dialog.c
+++ b/source3/utils/regedit_dialog.c
@@ -1027,8 +1027,10 @@ static WERROR handle_editor_input(struct edit_dialog *edit,
"Enter new size");
if (n) {
newlen = strtoul(n, NULL, 10);
+ edit->section = IN_DATA;
hexedit_resize_buffer(edit->buf, newlen);
hexedit_refresh(edit->buf);
+ hexedit_set_cursor(edit->buf);
talloc_free(n);
}
} else if (selection == DIALOG_CANCEL) {
diff --git a/source3/utils/regedit_hexedit.c b/source3/utils/regedit_hexedit.c
index e2864e3fae..8f1c2c72f8 100644
--- a/source3/utils/regedit_hexedit.c
+++ b/source3/utils/regedit_hexedit.c
@@ -93,8 +93,12 @@ static size_t bytes_per_screen(WINDOW *win)
void hexedit_set_cursor(struct hexedit *buf)
{
werase(buf->status_line);
- wprintw(buf->status_line, "Len:%lu Off:%lu Val:0x%X", buf->len,
- buf->cursor_offset, buf->data[buf->cursor_offset]);
+ if (buf->len) {
+ wprintw(buf->status_line, "Len:%lu Off:%lu Val:0x%X", buf->len,
+ buf->cursor_offset, buf->data[buf->cursor_offset]);
+ } else {
+ wprintw(buf->status_line, "Len:%lu (empty)", buf->len);
+ }
wmove(buf->win, buf->cursor_y, buf->cursor_x);
wcursyncup(buf->win);
wsyncup(buf->win);
@@ -108,6 +112,10 @@ void hexedit_refresh(struct hexedit *buf)
size_t off;
werase(buf->win);
+ if (buf->len == 0) {
+ mvwprintw(buf->win, 0, 0, "%08X", 0);
+ return;
+ }
end = buf->offset + bytes_per_screen(buf->win);
if (end > buf->len) {
@@ -294,6 +302,9 @@ static void cursor_right(struct hexedit *buf)
{
int new_x = buf->cursor_x + 1;
+ if (buf->len == 0) {
+ return;
+ }
if (new_x == ASCII_COL_END) {
return;
}
@@ -335,6 +346,10 @@ static void do_edit(struct hexedit *buf, int c)
{
uint8_t *byte;
+ if (buf->len == 0) {
+ return;
+ }
+
byte = buf->data + buf->cursor_offset;
if (buf->cursor_x >= ASCII_COL) {