tags 268495 patch user ubuntu-de...@lists.ubuntu.com usertags 268495 ubuntu-patch jaunty thanks
On Thu, Oct 28, 2004 at 08:28:20PM +0100, Colin Watson wrote: > It's still possible to hang parted_server by entering an empty name, > which is a separate problem: the implementation of the SET_NAME command > uses fscanf(" %a[^\n]"), which never returns if you only send > whitespace. Here's a patch which I think fixes this. I've only tested this in a test harness, not yet in a full installation, but I think it's right. -- Colin Watson [cjwat...@ubuntu.com]
Index: parted_server.c =================================================================== --- parted_server.c (revision 56922) +++ parted_server.c (working copy) @@ -118,7 +118,38 @@ the function `scanf' */ #define iscanf(...) fscanf(infifo,__VA_ARGS__) +/* Read the remainder of this line from the input FIFO, skipping leading + * whitespace. Sets *str to NULL if there was no data left in the FIFO (as + * opposed to merely optional leading whitespace followed by a newline, + * indicating an empty argument following the whitespace; in that case, set + * *str to the empty string). Caller is expected to free *str. + */ void +iscan_line(char **str) +{ + int c; + + *str = NULL; + + c = fgetc(infifo); + if (c == EOF) + return; + while (c != EOF && c != '\n') { + if (isspace((unsigned char) c)) + c = fgetc(infifo); + else { + ungetc(c, infifo); + break; + } + } + + if (c == EOF || c == '\n') + *str = calloc(1, 1); + else + iscanf("%a[^\n]", str); +} + +void synchronise_with_client() { char *str; @@ -287,7 +318,8 @@ oprintf("\n"); if (timer_was_started) start_timer(); - if (1 != iscanf(" %a[^\n]", &str)) + iscan_line(&str); + if (!str) critical_error("No data in infifo."); if (!strcmp(str, "unhandled")) { log("User canceled exception handler"); @@ -1471,7 +1503,8 @@ for (flag = first; flag <= last; flag++) states[flag - first] = false; while (1) { - if (1 != iscanf(" %a[^\n]", &str)) + iscan_line(&str); + if (!str) critical_error("No data in infifo!"); if (!strcmp(str, "NO_MORE")) break; @@ -1530,7 +1563,8 @@ if (part == NULL || !ped_partition_is_active(part)) critical_error("No such active partition: %s", id); log("Partition found (%s)", id); - if (1 != iscanf(" %a[^\n]", &name)) + iscan_line(&name); + if (!name) critical_error("No data in infifo!"); log("Changing name to %s", name); open_out();