From: Charlie Brej Date: Sat, 3 Jan 2009 21:33:56 +0000 (+0000) Subject: Allow client request answers to be greater than 255 characters. X-Git-Tag: 0.7.0~232 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=42abc981574bf5abe2f7ac94b7a21459d479ac44;p=thirdparty%2Fplymouth.git Allow client request answers to be greater than 255 characters. The new limit is 2^32. This only affects the replies to the client. Data sent along with requests (e.g. password prompt) remain limited to <256 characters. Two new functions have been added to the ply-utils (ply_read_uint32 and ply_write_uint32) which receive/transmit 32bit numbers on FD streams. AFAICT in function ply_boot_client_process_incoming_replies the answer was not NUL terminated, which may have caused some of the password error bugs. --- diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index 57bfda75..7354d3a9 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -244,7 +244,7 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client) ply_boot_client_request_t *request; bool processed_reply; uint8_t byte[2] = ""; - uint8_t size; + uint32_t size; assert (client != NULL); @@ -268,20 +268,21 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client) request->handler (request->user_data, client); else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, sizeof (uint8_t)) == 0) { - char answer[257] = ""; + char *answer; - /* FIXME: should make this 4 bytes instead of 1 - */ - if (!ply_read (client->socket_fd, &size, sizeof (uint8_t))) + if (!ply_read_uint32 (client->socket_fd, &size)) goto out; - + + answer = malloc ((size+1) * sizeof(char)); if (size > 0) { if (!ply_read (client->socket_fd, answer, size)) goto out; } + answer[size] = '\0'; ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, answer, client); + free(answer); } else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS, sizeof (uint8_t)) == 0) { @@ -295,7 +296,7 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client) array = NULL; answers = NULL; - if (!ply_read (client->socket_fd, &size, sizeof (uint8_t))) + if (!ply_read_uint32 (client->socket_fd, &size)) goto out; assert (size > 0); diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 25371a1e..25f9e064 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -359,6 +359,20 @@ ply_write (int fd, return bytes_left_to_write == 0; } +bool +ply_write_uint32 (int fd, + uint32_t value) +{ + uint8_t buffer[4]; + + buffer[0] = (value >> 0) & 0xFF; + buffer[1] = (value >> 8) & 0xFF; + buffer[2] = (value >> 16) & 0xFF; + buffer[3] = (value >> 24) & 0xFF; + + return ply_write (fd, buffer, 4 * sizeof (uint8_t)); +} + static ssize_t ply_read_some_bytes (int fd, void *buffer, @@ -414,6 +428,22 @@ ply_read (int fd, return read_was_successful; } +bool +ply_read_uint32 (int fd, + uint32_t *value) +{ + uint8_t buffer[4]; + + if (!ply_read (fd, buffer, 4 * sizeof (uint8_t))) + return false; + + *value = (buffer[0] << 0) | + (buffer[1] << 8) | + (buffer[2] << 16) | + (buffer[3] << 24); + return true; +} + bool ply_fd_has_data (int fd) { diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index 3d3077d6..53280688 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -58,9 +58,13 @@ bool ply_get_credentials_from_fd (int fd, bool ply_write (int fd, const void *buffer, size_t number_of_bytes); +bool ply_write_uint32 (int fd, + uint32_t value); bool ply_read (int fd, void *buffer, size_t number_of_bytes); +bool ply_read_uint32 (int fd, + uint32_t *value); bool ply_fd_has_data (int fd); bool ply_fd_can_take_data (int fd); diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index 6c38690a..8615f3bd 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -227,7 +227,7 @@ static void ply_boot_connection_send_answer (ply_boot_connection_t *connection, const char *answer) { - uint8_t size; + uint32_t size; /* splash plugin isn't able to ask for password, * punt to client @@ -241,18 +241,13 @@ ply_boot_connection_send_answer (ply_boot_connection_t *connection, } else { - /* FIXME: support up to 4 billion - */ - if (strlen (answer) > 255) - ply_error ("answer to long to fit in buffer"); - - size = (uint8_t) strlen (answer); + size = strlen (answer); if (!ply_write (connection->fd, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER)) || - !ply_write (connection->fd, - &size, sizeof (uint8_t)) || + !ply_write_uint32 (connection->fd, + size) || !ply_write (connection->fd, answer, size)) ply_error ("could not write bytes: %m"); @@ -377,7 +372,7 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) ply_list_node_t *node; ply_buffer_t *buffer; size_t buffer_size; - uint8_t size; + uint32_t size; buffer = ply_buffer_new (); @@ -413,20 +408,13 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) } else { - /* FIXME: This is likely too small, we need to add another - * layer of indirection that says how many bytes the size - * is. - */ - if (buffer_size > 255) - ply_error ("passwords too long to fit in buffer"); - size = buffer_size; if (!ply_write (connection->fd, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS, strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS)) || - !ply_write (connection->fd, - &size, sizeof (uint8_t)) || + !ply_write_uint32 (connection->fd, + size) || !ply_write (connection->fd, ply_buffer_get_bytes (buffer), size)) ply_error ("could not write bytes: %m");