librpc: Use portable format specifiers
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 10 May 2021 22:29:31 +0000 (10:29 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 27 Sep 2023 02:43:28 +0000 (02:43 +0000)
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
librpc/rpc/binding.c
librpc/rpc/dcerpc_util.c
librpc/rpc/dcesrv_core.c
librpc/tools/ndrdump.c

index 3e2a4468f4d04a2e3022eb24986c1e9d3d909428..8cb42d67914258859f16c159f8e1082e25d735b4 100644 (file)
@@ -194,13 +194,13 @@ const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor)
                        return "NB_IPX";
 
                case EPM_PROTOCOL_HTTP:
-                       return talloc_asprintf(mem_ctx, "HTTP:%d", epm_floor->rhs.http.port);
+                       return talloc_asprintf(mem_ctx, "HTTP:%"PRIu16, epm_floor->rhs.http.port);
 
                case EPM_PROTOCOL_TCP:
-                       return talloc_asprintf(mem_ctx, "TCP:%d", epm_floor->rhs.tcp.port);
+                       return talloc_asprintf(mem_ctx, "TCP:%"PRIu16, epm_floor->rhs.tcp.port);
 
                case EPM_PROTOCOL_UDP:
-                       return talloc_asprintf(mem_ctx, "UDP:%d", epm_floor->rhs.udp.port);
+                       return talloc_asprintf(mem_ctx, "UDP:%"PRIu16, epm_floor->rhs.udp.port);
 
                default:
                        return talloc_asprintf(mem_ctx, "UNK(%02x):", epm_floor->lhs.protocol);
@@ -987,15 +987,15 @@ char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor
        switch (epm_floor->lhs.protocol) {
        case EPM_PROTOCOL_TCP:
                if (epm_floor->rhs.tcp.port == 0) return NULL;
-               return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.tcp.port);
+               return talloc_asprintf(mem_ctx, "%"PRIu16, epm_floor->rhs.tcp.port);
 
        case EPM_PROTOCOL_UDP:
                if (epm_floor->rhs.udp.port == 0) return NULL;
-               return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.udp.port);
+               return talloc_asprintf(mem_ctx, "%"PRIu16, epm_floor->rhs.udp.port);
 
        case EPM_PROTOCOL_HTTP:
                if (epm_floor->rhs.http.port == 0) return NULL;
-               return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.http.port);
+               return talloc_asprintf(mem_ctx, "%"PRIu16, epm_floor->rhs.http.port);
 
        case EPM_PROTOCOL_IP:
                return talloc_strdup(mem_ctx, epm_floor->rhs.ip.ipaddr);
@@ -1022,10 +1022,10 @@ char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor
                return NULL;
 
        case EPM_PROTOCOL_VINES_SPP:
-               return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.vines_spp.port);
+               return talloc_asprintf(mem_ctx, "%"PRIu16, epm_floor->rhs.vines_spp.port);
 
        case EPM_PROTOCOL_VINES_IPC:
-               return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.vines_ipc.port);
+               return talloc_asprintf(mem_ctx, "%"PRIu16, epm_floor->rhs.vines_ipc.port);
 
        case EPM_PROTOCOL_STREETTALK:
                return talloc_strdup(mem_ctx, epm_floor->rhs.streettalk.streettalk);
index a3a734b0c090e64401d0309a005e21c3ff4fe4c5..a1f311e57b7586c1d32b92aa2f707ac56acbed88 100644 (file)
@@ -331,9 +331,9 @@ NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
        }
        if (max_pad_len < auth->auth_pad_length) {
                DEBUG(1, (__location__ ": ERROR: pad length to large. "
-                         "max %u got %u\n",
-                         (unsigned)max_pad_len,
-                         (unsigned)auth->auth_pad_length));
+                         "max %"PRIu32" got %"PRIu8"\n",
+                         max_pad_len,
+                         auth->auth_pad_length));
                talloc_free(ndr);
                ZERO_STRUCTP(auth);
                return NT_STATUS_RPC_PROTOCOL_ERROR;
@@ -357,12 +357,12 @@ NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
 
        if (data_and_pad < auth->auth_pad_length) {
                DBG_WARNING(__location__ ": ERROR: pad length too long. "
-                           "Calculated %u (pkt_trailer->length=%u - auth_length=%u) "
-                           "was less than auth_pad_length=%u\n",
-                           (unsigned)data_and_pad,
-                           (unsigned)pkt_trailer->length,
-                           (unsigned)auth_length,
-                           (unsigned)auth->auth_pad_length);
+                           "Calculated %"PRIu16" (pkt_trailer->length=%zu - auth_length=%"PRIu16") "
+                           "was less than auth_pad_length=%"PRIu8"\n",
+                           data_and_pad,
+                           pkt_trailer->length,
+                           auth_length,
+                           auth->auth_pad_length);
                talloc_free(ndr);
                ZERO_STRUCTP(auth);
                return NT_STATUS_RPC_PROTOCOL_ERROR;
@@ -370,14 +370,14 @@ NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
 
        if (auth_data_only && data_and_pad > auth->auth_pad_length) {
                DBG_WARNING(__location__ ": ERROR: auth_data_only pad length mismatch. "
-                           "Client sent a longer BIND packet than expected by %u bytes "
-                           "(pkt_trailer->length=%u - auth_length=%u) "
-                           "= %u auth_pad_length=%u\n",
-                           (unsigned)data_and_pad - (unsigned)auth->auth_pad_length,
-                           (unsigned)pkt_trailer->length,
-                           (unsigned)auth_length,
-                           (unsigned)data_and_pad,
-                           (unsigned)auth->auth_pad_length);
+                           "Client sent a longer BIND packet than expected by %"PRIu16" bytes "
+                           "(pkt_trailer->length=%zu - auth_length=%"PRIu16") "
+                           "= %"PRIu16" auth_pad_length=%"PRIu8"\n",
+                           data_and_pad - auth->auth_pad_length,
+                           pkt_trailer->length,
+                           auth_length,
+                           data_and_pad,
+                           auth->auth_pad_length);
                talloc_free(ndr);
                ZERO_STRUCTP(auth);
                return NT_STATUS_RPC_PROTOCOL_ERROR;
@@ -385,19 +385,19 @@ NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
 
        if (auth_data_only && data_and_pad != auth->auth_pad_length) {
                DBG_WARNING(__location__ ": ERROR: auth_data_only pad length mismatch. "
-                           "Calculated %u (pkt_trailer->length=%u - auth_length=%u) "
-                           "but auth_pad_length=%u\n",
-                           (unsigned)data_and_pad,
-                           (unsigned)pkt_trailer->length,
-                           (unsigned)auth_length,
-                           (unsigned)auth->auth_pad_length);
+                           "Calculated %"PRIu16" (pkt_trailer->length=%zu - auth_length=%"PRIu16") "
+                           "but auth_pad_length=%"PRIu8"\n",
+                           data_and_pad,
+                           pkt_trailer->length,
+                           auth_length,
+                           auth->auth_pad_length);
                talloc_free(ndr);
                ZERO_STRUCTP(auth);
                return NT_STATUS_RPC_PROTOCOL_ERROR;
        }
 
-       DBG_DEBUG("auth_pad_length %u\n",
-                 (unsigned)auth->auth_pad_length);
+       DBG_DEBUG("auth_pad_length %"PRIu8"\n",
+                 auth->auth_pad_length);
 
        talloc_steal(mem_ctx, auth->credentials.data);
        talloc_free(ndr);
@@ -1121,7 +1121,7 @@ void dcerpc_log_packet(const char *packet_log_dir,
                char *name=NULL;
                int ret;
                bool saved;
-               ret = asprintf(&name, "%s/%s-%u.%d.%s.%s",
+               ret = asprintf(&name, "%s/%s-%"PRIu32".%d.%s.%s",
                               packet_log_dir, interface_name, opnum, i,
                               (flags&NDR_IN)?"in":"out",
                               why);
index 09ea68122494211af1bf0c7c32d4a1444f28fa2f..35fb7aa853dacaf1a249999b2501d166c55c6b96 100644 (file)
@@ -1934,7 +1934,7 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call)
                uint8_t extra_flags = 0;
                if (call->fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
                        /* we got an unknown call */
-                       DEBUG(3,(__location__ ": Unknown RPC call %u on %s\n",
+                       DEBUG(3,(__location__ ": Unknown RPC call %"PRIu16" on %s\n",
                                 call->pkt.u.request.opnum,
                                 call->context->iface->name));
                        dcesrv_save_call(call, "unknown");
@@ -1952,7 +1952,7 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call)
 
        if (pull->offset != pull->data_size) {
                dcesrv_save_call(call, "extrabytes");
-               DEBUG(3,("Warning: %d extra bytes in incoming RPC request\n",
+               DEBUG(3,("Warning: %"PRIu32" extra bytes in incoming RPC request\n",
                         pull->data_size - pull->offset));
        }
 
index 26f885ccd10096479ad57ff14d84af84d19f5e72..a81d8062443e258e447d2bcd1c6090c7d1dbb7dc 100644 (file)
@@ -220,9 +220,9 @@ static NTSTATUS ndrdump_pull_and_print_pipes(const char *function,
                         */
                        count = (uint32_t *)c;
 
-                       n = talloc_asprintf(c, "%s: %s[%llu]",
+                       n = talloc_asprintf(c, "%s: %s[%"PRIu64"]",
                                        function, pipes->pipes[i].name,
-                                       (unsigned long long)idx);
+                                       idx);
 
                        saved_mem_ctx = ndr_pull->current_mem_ctx;
                        ndr_pull->current_mem_ctx = c;
@@ -458,8 +458,8 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
 
        st = talloc_zero_size(mem_ctx, f->struct_size);
        if (!st) {
-               printf("Unable to allocate %d bytes for %s structure\n",
-                      (int)f->struct_size,
+               printf("Unable to allocate %zu bytes for %s structure\n",
+                      f->struct_size,
                       f->name);
                TALLOC_FREE(mem_ctx);
                exit(1);
@@ -467,9 +467,9 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
 
        v_st = talloc_zero_size(mem_ctx, f->struct_size);
        if (!v_st) {
-               printf("Unable to allocate %d bytes for %s validation "
+               printf("Unable to allocate %zu bytes for %s validation "
                       "structure\n",
-                      (int)f->struct_size,
+                      f->struct_size,
                       f->name);
                TALLOC_FREE(mem_ctx);
                exit(1);
@@ -511,7 +511,7 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
                }
 
                if (highest_ofs != ndr_pull->data_size) {
-                       printf("WARNING! %d unread bytes while parsing context file\n", ndr_pull->data_size - highest_ofs);
+                       printf("WARNING! %"PRIu32" unread bytes while parsing context file\n", ndr_pull->data_size - highest_ofs);
                }
 
                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
@@ -594,8 +594,8 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
        }
 
        if (sec_vt != NULL && sec_vt->count.count > 0) {
-               printf("SEC_VT: consumed %d bytes\n",
-                      (int)(blob.length - ndr_pull->data_size));
+               printf("SEC_VT: consumed %zu bytes\n",
+                      blob.length - ndr_pull->data_size);
                if (dumpdata) {
                        ndrdump_data(blob.data + ndr_pull->data_size,
                                     blob.length - ndr_pull->data_size,
@@ -629,7 +629,7 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
        }
 
        if (dumpdata) {
-               printf("%d bytes consumed\n", highest_ofs);
+               printf("%"PRIu32" bytes consumed\n", highest_ofs);
                ndrdump_data(blob.data, blob.length, dumpdata);
        }
 
@@ -639,7 +639,7 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
        }
 
        if (highest_ofs != ndr_pull->data_size) {
-               printf("WARNING! %d unread bytes\n", ndr_pull->data_size - highest_ofs);
+               printf("WARNING! %"PRIu32" unread bytes\n", ndr_pull->data_size - highest_ofs);
                ndrdump_data(ndr_pull->data+highest_ofs,
                             ndr_pull->data_size - highest_ofs,
                             dumpdata);
@@ -705,7 +705,7 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
                v_blob = ndr_push_blob(ndr_v_push);
 
                if (dumpdata) {
-                       printf("%ld bytes generated (validate)\n", (long)v_blob.length);
+                       printf("%zu bytes generated (validate)\n", v_blob.length);
                        ndrdump_data(v_blob.data, v_blob.length, dumpdata);
                }
 
@@ -733,7 +733,7 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
                }
 
                if (highest_v_ofs != ndr_v_pull->data_size) {
-                       printf("WARNING! %d unread bytes in validation\n",
+                       printf("WARNING! %"PRIu32" unread bytes in validation\n",
                               ndr_v_pull->data_size - highest_v_ofs);
                        ndrdump_data(ndr_v_pull->data + highest_v_ofs,
                                     ndr_v_pull->data_size - highest_v_ofs,
@@ -748,13 +748,13 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
                             flags, v_st);
 
                if (blob.length != v_blob.length) {
-                       printf("WARNING! orig bytes:%llu validated pushed bytes:%llu\n", 
-                              (unsigned long long)blob.length, (unsigned long long)v_blob.length);
+                       printf("WARNING! orig bytes:%zu validated pushed bytes:%zu\n",
+                              blob.length, v_blob.length);
                }
 
                if (highest_ofs != highest_v_ofs) {
-                       printf("WARNING! orig pulled bytes:%llu validated pulled bytes:%llu\n", 
-                              (unsigned long long)highest_ofs, (unsigned long long)highest_v_ofs);
+                       printf("WARNING! orig pulled bytes:%"PRIu32" validated pulled bytes:%"PRIu32"\n",
+                              highest_ofs, highest_v_ofs);
                }
 
                differ = false;
@@ -777,8 +777,8 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
                        }
                }
                if (differ) {
-                       printf("WARNING! orig and validated differ at byte 0x%02X (%u)\n", i, i);
-                       printf("WARNING! orig byte[0x%02X] = 0x%02X validated byte[0x%02X] = 0x%02X\n",
+                       printf("WARNING! orig and validated differ at byte 0x%02"PRIX32" (%"PRIu32")\n", i, i);
+                       printf("WARNING! orig byte[0x%02"PRIX32"] = 0x%02"PRIX8" validated byte[0x%02"PRIX32"] = 0x%02"PRIX8"\n",
                                i, byte_a, i, byte_b);
                        ndrdump_data_diff(blob.data, blob.length,
                                          v_blob.data, v_blob.length,