diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-03-22 17:33:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-03-22 17:33:59 +0000 |
commit | 728a3f8c8a1098dea35732c3ad59fb8d60ee8e0f (patch) | |
tree | 40c5157956a84df91ed09c8d620cf2d83626941e /src/util/strings.c | |
parent | 8bcc7b48e6e2e07ee5ba4da0e0c93714c6698c4d (diff) | |
download | gnunet-728a3f8c8a1098dea35732c3ad59fb8d60ee8e0f.tar.gz gnunet-728a3f8c8a1098dea35732c3ad59fb8d60ee8e0f.zip |
-fixing string decoder issue for input sizes of a multiple of 5
Diffstat (limited to 'src/util/strings.c')
-rw-r--r-- | src/util/strings.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/util/strings.c b/src/util/strings.c index e9b5b3c21..8bbc904bc 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -817,7 +817,7 @@ GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out, size_t | |||
817 | * @param enc the encoding | 817 | * @param enc the encoding |
818 | * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) | 818 | * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) |
819 | * @param out location where to store the decoded data | 819 | * @param out location where to store the decoded data |
820 | * @param out_size sizeof the output buffer | 820 | * @param out_size size of the output buffer |
821 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | 821 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding |
822 | */ | 822 | */ |
823 | int | 823 | int |
@@ -831,31 +831,40 @@ GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen, | |||
831 | int ret; | 831 | int ret; |
832 | int shift; | 832 | int shift; |
833 | unsigned char *uout; | 833 | unsigned char *uout; |
834 | int encoded_len = out_size * 8; | 834 | unsigned int encoded_len = out_size * 8; |
835 | 835 | ||
836 | if (0 == enclen) | ||
837 | { | ||
838 | if (0 == out_size) | ||
839 | return GNUNET_OK; | ||
840 | return GNUNET_SYSERR; | ||
841 | } | ||
836 | uout = out; | 842 | uout = out; |
837 | if (encoded_len % 5 > 0) | 843 | wpos = out_size; |
844 | rpos = enclen; | ||
845 | if ((encoded_len % 5) > 0) | ||
838 | { | 846 | { |
839 | vbit = encoded_len % 5; /* padding! */ | 847 | vbit = encoded_len % 5; /* padding! */ |
840 | shift = 5 - vbit; | 848 | shift = 5 - vbit; |
849 | bits = (ret = getValue__ (enc[--rpos])) >> (5 - (encoded_len % 5)); | ||
841 | } | 850 | } |
842 | else | 851 | else |
843 | { | 852 | { |
844 | vbit = 0; | 853 | vbit = 5; |
845 | shift = 0; | 854 | shift = 0; |
855 | bits = (ret = getValue__ (enc[--rpos])); | ||
846 | } | 856 | } |
847 | if ((encoded_len + shift) / 5 != enclen) | 857 | if ((encoded_len + shift) / 5 != enclen) |
848 | return GNUNET_SYSERR; | 858 | return GNUNET_SYSERR; |
849 | |||
850 | wpos = out_size; | ||
851 | rpos = enclen; | ||
852 | bits = (ret = getValue__ (enc[--rpos])) >> (5 - encoded_len % 5); | ||
853 | if (-1 == ret) | 859 | if (-1 == ret) |
854 | return GNUNET_SYSERR; | 860 | return GNUNET_SYSERR; |
855 | while (wpos > 0) | 861 | while (wpos > 0) |
856 | { | 862 | { |
857 | if (0 == rpos) | 863 | if (0 == rpos) |
864 | { | ||
865 | GNUNET_break (0); | ||
858 | return GNUNET_SYSERR; | 866 | return GNUNET_SYSERR; |
867 | } | ||
859 | bits = ((ret = getValue__ (enc[--rpos])) << vbit) | bits; | 868 | bits = ((ret = getValue__ (enc[--rpos])) << vbit) | bits; |
860 | if (-1 == ret) | 869 | if (-1 == ret) |
861 | return GNUNET_SYSERR; | 870 | return GNUNET_SYSERR; |