From cd7a01c34fc4304ef8161ee617568f274ace5d24 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 18 Mar 2018 23:13:40 +0100 Subject: Windows: Update libzip to version 1.5.0 that include fixes for some security issues. --- src/Common/libzip/zip_extra_field_api.c | 111 ++++++++++++++------------------ 1 file changed, 50 insertions(+), 61 deletions(-) (limited to 'src/Common/libzip/zip_extra_field_api.c') diff --git a/src/Common/libzip/zip_extra_field_api.c b/src/Common/libzip/zip_extra_field_api.c index ed93944a..469abd2f 100644 --- a/src/Common/libzip/zip_extra_field_api.c +++ b/src/Common/libzip/zip_extra_field_api.c @@ -17,7 +17,7 @@ 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -36,8 +36,7 @@ ZIP_EXTERN int -zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags) -{ +zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_flags_t flags) { zip_dirent_t *de; if ((flags & ZIP_EF_BOTH) == 0) { @@ -49,28 +48,27 @@ zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zi zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) return -1; - + if (ZIP_IS_RDONLY(za)) { zip_error_set(&za->error, ZIP_ER_RDONLY, 0); return -1; } if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) - return -1; - + return -1; + de = za->entry[idx].changes; - + de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ZIP_EXTRA_FIELD_ALL, ef_idx, flags); return 0; } ZIP_EXTERN int -zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_flags_t flags) -{ +zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_flags_t flags) { zip_dirent_t *de; if ((flags & ZIP_EF_BOTH) == 0) { @@ -82,7 +80,7 @@ zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - + if (_zip_get_dirent(za, idx, 0, NULL) == NULL) return -1; @@ -90,10 +88,10 @@ zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i zip_error_set(&za->error, ZIP_ER_RDONLY, 0); return -1; } - + if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) - return -1; - + return -1; + de = za->entry[idx].changes; de->extra_fields = _zip_ef_delete_by_id(de->extra_fields, ef_id, ef_idx, flags); @@ -102,9 +100,8 @@ zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i ZIP_EXTERN const zip_uint8_t * -zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_uint16_t *idp, zip_uint16_t *lenp, zip_flags_t flags) -{ - static const zip_uint8_t empty[1] = { '\0' }; +zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_uint16_t *idp, zip_uint16_t *lenp, zip_flags_t flags) { + static const zip_uint8_t empty[1] = {'\0'}; zip_dirent_t *de; zip_extra_field_t *ef; @@ -115,7 +112,7 @@ zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_u return NULL; } - if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) return NULL; if (flags & ZIP_FL_LOCAL) @@ -123,7 +120,7 @@ zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_u return NULL; i = 0; - for (ef=de->extra_fields; ef; ef=ef->next) { + for (ef = de->extra_fields; ef; ef = ef->next) { if (ef->flags & flags & ZIP_EF_BOTH) { if (i < ef_idx) { i++; @@ -143,13 +140,11 @@ zip_file_extra_field_get(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zip_u zip_error_set(&za->error, ZIP_ER_NOENT, 0); return NULL; - } ZIP_EXTERN const zip_uint8_t * -zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_uint16_t *lenp, zip_flags_t flags) -{ +zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, zip_uint16_t *lenp, zip_flags_t flags) { zip_dirent_t *de; if ((flags & ZIP_EF_BOTH) == 0) { @@ -157,7 +152,7 @@ zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, return NULL; } - if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) return NULL; if (flags & ZIP_FL_LOCAL) @@ -169,8 +164,7 @@ zip_file_extra_field_get_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, ZIP_EXTERN zip_int16_t -zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) -{ +zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) { zip_dirent_t *de; zip_extra_field_t *ef; zip_uint16_t n; @@ -180,7 +174,7 @@ zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) return -1; } - if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) return -1; if (flags & ZIP_FL_LOCAL) @@ -188,7 +182,7 @@ zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) return -1; n = 0; - for (ef=de->extra_fields; ef; ef=ef->next) + for (ef = de->extra_fields; ef; ef = ef->next) if (ef->flags & flags & ZIP_EF_BOTH) n++; @@ -197,8 +191,7 @@ zip_file_extra_fields_count(zip_t *za, zip_uint64_t idx, zip_flags_t flags) ZIP_EXTERN zip_int16_t -zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_flags_t flags) -{ +zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_flags_t flags) { zip_dirent_t *de; zip_extra_field_t *ef; zip_uint16_t n; @@ -208,7 +201,7 @@ zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i return -1; } - if ((de=_zip_get_dirent(za, idx, flags, &za->error)) == NULL) + if ((de = _zip_get_dirent(za, idx, flags, &za->error)) == NULL) return -1; if (flags & ZIP_FL_LOCAL) @@ -216,7 +209,7 @@ zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i return -1; n = 0; - for (ef=de->extra_fields; ef; ef=ef->next) + for (ef = de->extra_fields; ef; ef = ef->next) if (ef->id == ef_id && (ef->flags & flags & ZIP_EF_BOTH)) n++; @@ -225,8 +218,7 @@ zip_file_extra_fields_count_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i ZIP_EXTERN int -zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags) -{ +zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_uint16_t ef_idx, const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags) { zip_dirent_t *de; zip_uint16_t ls, cs; zip_extra_field_t *ef, *ef_prev, *ef_new; @@ -239,20 +231,20 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_ui if (_zip_get_dirent(za, idx, 0, NULL) == NULL) return -1; - + if (ZIP_IS_RDONLY(za)) { zip_error_set(&za->error, ZIP_ER_RDONLY, 0); return -1; } - + if (ZIP_EF_IS_INTERNAL(ef_id)) { zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } if (_zip_file_extra_field_prepare_for_change(za, idx) < 0) - return -1; - + return -1; + de = za->entry[idx].changes; ef = de->extra_fields; @@ -260,7 +252,7 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_ui i = 0; found = 0; - for (; ef; ef=ef->next) { + for (; ef; ef = ef->next) { if (ef->id == ef_id && (ef->flags & flags & ZIP_EF_BOTH)) { if (i == ef_idx) { found = 1; @@ -294,8 +286,8 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_ui zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - - if ((ef_new=_zip_ef_new(ef_id, len, data, flags)) == NULL) { + + if ((ef_new = _zip_ef_new(ef_id, len, data, flags)) == NULL) { zip_error_set(&za->error, ZIP_ER_MEMORY, 0); return -1; } @@ -314,7 +306,7 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_ui ef->flags &= ~(flags & ZIP_EF_BOTH); ef_new->next = ef->next; ef->next = ef_new; - } + } } else if (ef_prev) { ef_new->next = ef_prev->next; @@ -322,45 +314,42 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_ui } else de->extra_fields = ef_new; - + return 0; } - int -_zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx) -{ +_zip_file_extra_field_prepare_for_change(zip_t *za, zip_uint64_t idx) { zip_entry_t *e; - + if (idx >= za->nentry) { - zip_error_set(&za->error, ZIP_ER_INVAL, 0); - return -1; + zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; } - - e = za->entry+idx; - + + e = za->entry + idx; + if (e->changes && (e->changes->changed & ZIP_DIRENT_EXTRA_FIELD)) - return 0; + return 0; if (e->orig) { if (_zip_read_local_ef(za, idx) < 0) return -1; } - + if (e->changes == NULL) { - if ((e->changes=_zip_dirent_clone(e->orig)) == NULL) { - zip_error_set(&za->error, ZIP_ER_MEMORY, 0); - return -1; - } + if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) { + zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + return -1; + } } - + if (e->orig && e->orig->extra_fields) { - if ((e->changes->extra_fields=_zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL) + if ((e->changes->extra_fields = _zip_ef_clone(e->orig->extra_fields, &za->error)) == NULL) return -1; } e->changes->changed |= ZIP_DIRENT_EXTRA_FIELD; - + return 0; } - -- cgit v1.2.3